From 0e4732edda4a0a35504e77542fba63b2fc8f6129 Mon Sep 17 00:00:00 2001 From: sairate Date: Sat, 7 Jun 2025 12:07:15 +0800 Subject: [PATCH] =?UTF-8?q?docs(B4050):=20=E6=B7=BB=E5=8A=A0=20GESP202409?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 高精算法---1.求n!的值/1.求n!的值.md | 53 +++++++++++++++++++++++++++ 高精算法---1.求n!的值/ni.cpp | 33 +++++++++++++++++ 高精算法---1.求n!的值/ni.pas | 34 +++++++++++++++++ 高精算法---1.求n!的值/ni_data/ni0.in | 1 + 高精算法---1.求n!的值/ni_data/ni0.out | 1 + 高精算法---1.求n!的值/ni_data/ni1.in | 1 + 高精算法---1.求n!的值/ni_data/ni1.out | 1 + 高精算法---1.求n!的值/ni_data/ni2.in | 1 + 高精算法---1.求n!的值/ni_data/ni2.out | 1 + 高精算法---1.求n!的值/ni_data/ni3.in | 1 + 高精算法---1.求n!的值/ni_data/ni3.out | 1 + 高精算法---1.求n!的值/ni_data/ni4.in | 1 + 高精算法---1.求n!的值/ni_data/ni4.out | 1 + 高精算法---1.求n!的值/ni_data/ni5.in | 1 + 高精算法---1.求n!的值/ni_data/ni5.out | 1 + 15 files changed, 132 insertions(+) create mode 100644 高精算法---1.求n!的值/1.求n!的值.md create mode 100644 高精算法---1.求n!的值/ni.cpp create mode 100644 高精算法---1.求n!的值/ni.pas create mode 100644 高精算法---1.求n!的值/ni_data/ni0.in create mode 100644 高精算法---1.求n!的值/ni_data/ni0.out create mode 100644 高精算法---1.求n!的值/ni_data/ni1.in create mode 100644 高精算法---1.求n!的值/ni_data/ni1.out create mode 100644 高精算法---1.求n!的值/ni_data/ni2.in create mode 100644 高精算法---1.求n!的值/ni_data/ni2.out create mode 100644 高精算法---1.求n!的值/ni_data/ni3.in create mode 100644 高精算法---1.求n!的值/ni_data/ni3.out create mode 100644 高精算法---1.求n!的值/ni_data/ni4.in create mode 100644 高精算法---1.求n!的值/ni_data/ni4.out create mode 100644 高精算法---1.求n!的值/ni_data/ni5.in create mode 100644 高精算法---1.求n!的值/ni_data/ni5.out diff --git a/高精算法---1.求n!的值/1.求n!的值.md b/高精算法---1.求n!的值/1.求n!的值.md new file mode 100644 index 0000000..5fc327c --- /dev/null +++ b/高精算法---1.求n!的值/1.求n!的值.md @@ -0,0 +1,53 @@ +## 1、求N!的值 【问题描述】 +用高精度方法,求N!的精确值(N以一般整数输入)。 +【输入样例】ni.in +```in +10 +``` +【输出样例】ni.out +```out +3628800 +``` + +```cpp +#include +#include +#include +using namespace std; + +// 高精度字符串乘法:res * num +string multiply(string res, int num) { + vector 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; +} + +``` \ No newline at end of file diff --git a/高精算法---1.求n!的值/ni.cpp b/高精算法---1.求n!的值/ni.cpp new file mode 100644 index 0000000..e779f03 --- /dev/null +++ b/高精算法---1.求n!的值/ni.cpp @@ -0,0 +1,33 @@ +#include +#include +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<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. diff --git a/高精算法---1.求n!的值/ni_data/ni0.in b/高精算法---1.求n!的值/ni_data/ni0.in new file mode 100644 index 0000000..f599e28 --- /dev/null +++ b/高精算法---1.求n!的值/ni_data/ni0.in @@ -0,0 +1 @@ +10 diff --git a/高精算法---1.求n!的值/ni_data/ni0.out b/高精算法---1.求n!的值/ni_data/ni0.out new file mode 100644 index 0000000..3fbd4a8 --- /dev/null +++ b/高精算法---1.求n!的值/ni_data/ni0.out @@ -0,0 +1 @@ +3628800 diff --git a/高精算法---1.求n!的值/ni_data/ni1.in b/高精算法---1.求n!的值/ni_data/ni1.in new file mode 100644 index 0000000..209e3ef --- /dev/null +++ b/高精算法---1.求n!的值/ni_data/ni1.in @@ -0,0 +1 @@ +20 diff --git a/高精算法---1.求n!的值/ni_data/ni1.out b/高精算法---1.求n!的值/ni_data/ni1.out new file mode 100644 index 0000000..c2f08cb --- /dev/null +++ b/高精算法---1.求n!的值/ni_data/ni1.out @@ -0,0 +1 @@ +2432902008176640000 diff --git a/高精算法---1.求n!的值/ni_data/ni2.in b/高精算法---1.求n!的值/ni_data/ni2.in new file mode 100644 index 0000000..c3f407c --- /dev/null +++ b/高精算法---1.求n!的值/ni_data/ni2.in @@ -0,0 +1 @@ +55 diff --git a/高精算法---1.求n!的值/ni_data/ni2.out b/高精算法---1.求n!的值/ni_data/ni2.out new file mode 100644 index 0000000..1c6f9f8 --- /dev/null +++ b/高精算法---1.求n!的值/ni_data/ni2.out @@ -0,0 +1 @@ +12696403353658275925965100847566516959580321051449436762275840000000000000 diff --git a/高精算法---1.求n!的值/ni_data/ni3.in b/高精算法---1.求n!的值/ni_data/ni3.in new file mode 100644 index 0000000..d22307c --- /dev/null +++ b/高精算法---1.求n!的值/ni_data/ni3.in @@ -0,0 +1 @@ +88 diff --git a/高精算法---1.求n!的值/ni_data/ni3.out b/高精算法---1.求n!的值/ni_data/ni3.out new file mode 100644 index 0000000..3602271 --- /dev/null +++ b/高精算法---1.求n!的值/ni_data/ni3.out @@ -0,0 +1 @@ +185482642257398439114796845645546284380220968949399346684421580986889562184028199319100141244804501828416633516851200000000000000000000 diff --git a/高精算法---1.求n!的值/ni_data/ni4.in b/高精算法---1.求n!的值/ni_data/ni4.in new file mode 100644 index 0000000..6a4573e --- /dev/null +++ b/高精算法---1.求n!的值/ni_data/ni4.in @@ -0,0 +1 @@ +133 diff --git a/高精算法---1.求n!的值/ni_data/ni4.out b/高精算法---1.求n!的值/ni_data/ni4.out new file mode 100644 index 0000000..1f28ff5 --- /dev/null +++ b/高精算法---1.求n!的值/ni_data/ni4.out @@ -0,0 +1 @@ +14872707060906857289084508911813048098675809251055070300508818286592035566485075754388082124671571841702793317081960037166525246368924700537538282948117301741317436012998958826217903503076596121600000000000000000000000000000000 diff --git a/高精算法---1.求n!的值/ni_data/ni5.in b/高精算法---1.求n!的值/ni_data/ni5.in new file mode 100644 index 0000000..51b4008 --- /dev/null +++ b/高精算法---1.求n!的值/ni_data/ni5.in @@ -0,0 +1 @@ +345 diff --git a/高精算法---1.求n!的值/ni_data/ni5.out b/高精算法---1.求n!的值/ni_data/ni5.out new file mode 100644 index 0000000..eed4369 --- /dev/null +++ b/高精算法---1.求n!的值/ni_data/ni5.out @@ -0,0 +1 @@ +24215638650792346558700053691985855570120556040258652734839783267039961720178323593174739047913617079695531502689473012213820889134885853992818438056445080201482863675240494802269823110125881000284687377104376400792200165127855908498047507347955446603093964326987087311394274684237308398502911304969719715098068025497504900730580217016573270011698467378924291550780873605154736879542602554635558428265690302091342359471863508627516511203478353542187151045838267239168928747525890559708487655213488727530884968558716385000436989129479527833010340517760688345368715729020015336862534353876914871201776699205878662858555857265544230999178449256448000000000000000000000000000000000000000000000000000000000000000000000000000000000000