docs(B4050): 添加 GESP202409
This commit is contained in:
parent
70714e15d2
commit
0e4732edda
53
高精算法---1.求n!的值/1.求n!的值.md
Normal file
53
高精算法---1.求n!的值/1.求n!的值.md
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
## 1、求N!的值 【问题描述】
|
||||||
|
用高精度方法,求N!的精确值(N以一般整数输入)。
|
||||||
|
【输入样例】ni.in
|
||||||
|
```in
|
||||||
|
10
|
||||||
|
```
|
||||||
|
【输出样例】ni.out
|
||||||
|
```out
|
||||||
|
3628800
|
||||||
|
```
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
#include<iostream>
|
||||||
|
#include<string>
|
||||||
|
#include<vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// 高精度字符串乘法:res * num
|
||||||
|
string multiply(string res, int num) {
|
||||||
|
vector<int> temp;
|
||||||
|
int carry = 0;
|
||||||
|
for (int i = res.size() - 1; i >= 0; i--) {
|
||||||
|
int product = (res[i] - '0') * num + carry;
|
||||||
|
temp.push_back(product % 10);
|
||||||
|
carry = product / 10;
|
||||||
|
}
|
||||||
|
while (carry) {
|
||||||
|
temp.push_back(carry % 10);
|
||||||
|
carry /= 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 把结果翻转回来
|
||||||
|
string result;
|
||||||
|
for (int i = temp.size() - 1; i >= 0; i--) {
|
||||||
|
result += temp[i] + '0';
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int n;
|
||||||
|
cin >> n;
|
||||||
|
string result = "1";
|
||||||
|
|
||||||
|
for (int i = 2; i <= n; i++) {
|
||||||
|
result = multiply(result, i);
|
||||||
|
}
|
||||||
|
reverse(result.begin(), result.end());
|
||||||
|
cout << result << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
33
高精算法---1.求n!的值/ni.cpp
Normal file
33
高精算法---1.求n!的值/ni.cpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#include<iostream>
|
||||||
|
#include<cstring>
|
||||||
|
using namespace std;
|
||||||
|
int a[100000],n,i,y,xy[100000];
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
cin>>n;
|
||||||
|
a[0]=1;
|
||||||
|
a[1]=1;
|
||||||
|
for (y=1;y<=n;y++)
|
||||||
|
{
|
||||||
|
memset(xy,0,sizeof(xy));
|
||||||
|
xy[0]=a[0];
|
||||||
|
for (i=1;i<=a[0];i++)
|
||||||
|
{
|
||||||
|
xy[i]+=a[i]*y;
|
||||||
|
xy[i+1]=xy[i]/10;
|
||||||
|
xy[i]%=10;
|
||||||
|
}
|
||||||
|
while (xy[xy[0]+1]>0)
|
||||||
|
{
|
||||||
|
xy[xy[0]+2]=xy[xy[0]+1]/10;
|
||||||
|
xy[xy[0]+1]%=10;
|
||||||
|
xy[0]++;
|
||||||
|
}
|
||||||
|
for (i=1;i<=xy[0];i++) a[i]=xy[i];
|
||||||
|
a[0]=xy[0];
|
||||||
|
}
|
||||||
|
for (i=a[0];i>=1;i--) cout<<a[i];
|
||||||
|
cout<<endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
34
高精算法---1.求n!的值/ni.pas
Normal file
34
高精算法---1.求n!的值/ni.pas
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
var
|
||||||
|
i,j,n,w : longint;
|
||||||
|
a : array[1..1000] of integer;
|
||||||
|
|
||||||
|
procedure fact(k : longint);
|
||||||
|
var
|
||||||
|
x,i : longint;
|
||||||
|
begin
|
||||||
|
x := 0;
|
||||||
|
for i := 1 to w do
|
||||||
|
begin
|
||||||
|
a[i] := a[i]*k+x;
|
||||||
|
x := a[i] div 10;
|
||||||
|
a[i] := a[i] mod 10;
|
||||||
|
end;
|
||||||
|
while x>0 DO
|
||||||
|
begin
|
||||||
|
w := w+1;
|
||||||
|
a[w] := x mod 10;
|
||||||
|
x := x div 10;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
assign(input,'ni.in'); reset(input);
|
||||||
|
assign(output,'ni.out'); rewrite(output);
|
||||||
|
a[1] := 1;
|
||||||
|
w := 1;
|
||||||
|
readln(n);
|
||||||
|
for i := 1 to n do fact(i);
|
||||||
|
for j := w downto 1 do write(a[j]);
|
||||||
|
writeln;
|
||||||
|
close(input); close(output);
|
||||||
|
end.
|
||||||
1
高精算法---1.求n!的值/ni_data/ni0.in
Normal file
1
高精算法---1.求n!的值/ni_data/ni0.in
Normal file
@ -0,0 +1 @@
|
|||||||
|
10
|
||||||
1
高精算法---1.求n!的值/ni_data/ni0.out
Normal file
1
高精算法---1.求n!的值/ni_data/ni0.out
Normal file
@ -0,0 +1 @@
|
|||||||
|
3628800
|
||||||
1
高精算法---1.求n!的值/ni_data/ni1.in
Normal file
1
高精算法---1.求n!的值/ni_data/ni1.in
Normal file
@ -0,0 +1 @@
|
|||||||
|
20
|
||||||
1
高精算法---1.求n!的值/ni_data/ni1.out
Normal file
1
高精算法---1.求n!的值/ni_data/ni1.out
Normal file
@ -0,0 +1 @@
|
|||||||
|
2432902008176640000
|
||||||
1
高精算法---1.求n!的值/ni_data/ni2.in
Normal file
1
高精算法---1.求n!的值/ni_data/ni2.in
Normal file
@ -0,0 +1 @@
|
|||||||
|
55
|
||||||
1
高精算法---1.求n!的值/ni_data/ni2.out
Normal file
1
高精算法---1.求n!的值/ni_data/ni2.out
Normal file
@ -0,0 +1 @@
|
|||||||
|
12696403353658275925965100847566516959580321051449436762275840000000000000
|
||||||
1
高精算法---1.求n!的值/ni_data/ni3.in
Normal file
1
高精算法---1.求n!的值/ni_data/ni3.in
Normal file
@ -0,0 +1 @@
|
|||||||
|
88
|
||||||
1
高精算法---1.求n!的值/ni_data/ni3.out
Normal file
1
高精算法---1.求n!的值/ni_data/ni3.out
Normal file
@ -0,0 +1 @@
|
|||||||
|
185482642257398439114796845645546284380220968949399346684421580986889562184028199319100141244804501828416633516851200000000000000000000
|
||||||
1
高精算法---1.求n!的值/ni_data/ni4.in
Normal file
1
高精算法---1.求n!的值/ni_data/ni4.in
Normal file
@ -0,0 +1 @@
|
|||||||
|
133
|
||||||
1
高精算法---1.求n!的值/ni_data/ni4.out
Normal file
1
高精算法---1.求n!的值/ni_data/ni4.out
Normal file
@ -0,0 +1 @@
|
|||||||
|
14872707060906857289084508911813048098675809251055070300508818286592035566485075754388082124671571841702793317081960037166525246368924700537538282948117301741317436012998958826217903503076596121600000000000000000000000000000000
|
||||||
1
高精算法---1.求n!的值/ni_data/ni5.in
Normal file
1
高精算法---1.求n!的值/ni_data/ni5.in
Normal file
@ -0,0 +1 @@
|
|||||||
|
345
|
||||||
1
高精算法---1.求n!的值/ni_data/ni5.out
Normal file
1
高精算法---1.求n!的值/ni_data/ni5.out
Normal file
@ -0,0 +1 @@
|
|||||||
|
24215638650792346558700053691985855570120556040258652734839783267039961720178323593174739047913617079695531502689473012213820889134885853992818438056445080201482863675240494802269823110125881000284687377104376400792200165127855908498047507347955446603093964326987087311394274684237308398502911304969719715098068025497504900730580217016573270011698467378924291550780873605154736879542602554635558428265690302091342359471863508627516511203478353542187151045838267239168928747525890559708487655213488727530884968558716385000436989129479527833010340517760688345368715729020015336862534353876914871201776699205878662858555857265544230999178449256448000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
Loading…
x
Reference in New Issue
Block a user