denghuolanshan_1004 @ 2023-02-14 17:52:22
#include <bits/stdc++.h>
using namespace std;
int main(){
int a;
int b=1;
cin>>a;
int c=0;
for (int i=1;i<=a;i++){
for (int j=1;j<=i;j++){
b*=j;
}
c+=b;
b=1;
}
cout<<b<<endl;
return 0;
}
by ShieHere @ 2023-02-14 17:55:36
这题要用高精度
by Loser_Syx @ 2023-02-14 17:56:16
lz的码风真好看
by denghuolanshan_1004 @ 2023-02-14 17:57:53
@Saint_ying_xtf 啥意思
by Pwtking @ 2023-02-14 18:14:34
@denghuolanshanchu 高精度就是当一个数据连longlong都存不下的时候的储存数据方式。建议先看一下高精度的模板,理解一下
by Fading_Happiness @ 2023-02-14 18:24:14
@denghuolanshanchu
cout<<b<<endl;
改为
cout << c << endl;
下次发帖子前先自己测测样例检查下吧(((
by denghuolanshan_1004 @ 2023-02-14 18:25:29
嗯嗯~~
by Fading_Happiness @ 2023-02-14 18:32:57
@denghuolanshanchu
另外,由于高精度的原因,需要P1303(高精度加法)和P1601(高精度乘法)两道题作为铺垫
by fengziyi @ 2023-02-14 18:48:37
@denghuolanshanchu
顺手附上刚写的热乎高精加和高精乘
// add
#include <iostream>
#include <cstring>
#define longint long long
#define reg register
#define qwq puts("fzy qwq ~");
using namespace std;
string str1, str2;
int a[210], b[210];
int ans[210], e;
int main()
{
cin >> str1;
cin >> str2;
int lena = str1.size();
int lenb = str2.size();
int limit = max(lena, lenb);
for (reg int i = 0; i < lena; ++i)
a[lena - i - 1] = str1[i] - '0';
for (reg int i = 0; i < lenb; ++i)
b[lenb - i - 1] = str2[i] - '0';
for (reg int i = 0; i <= limit; ++i)
{
ans[i] += ( a[i] + b[i] );
ans[i + 1] += ans[i] / 10 ;
ans[i] %= 10;
}
for (reg int i = limit + 1; i >= 0; --i)
if (ans[i] != 0)
{
e = i;
break;
}
// cout << e << endl;
for (reg int i = e; i >= 0; --i)
cout << ans[i];
return 0;
}
// mul
#include <iostream>
#include <cstring>
#define longint long long
#define reg register
#define qwq puts("fzy qwq ~");
using namespace std;
string stra, strb;
int a[510], b[510];
int ans[510];
int len;
int main()
{
freopen("mul.in", "r", stdin );
freopen("mul.out", "w", stdout);
cin >> stra >> strb;
a[0] = stra.size();
b[0] = strb.size();
for (reg int i = 1; i <= a[0]; ++i)
a[i] = stra[a[0] - i] - '0';
for (reg int i = 1; i <= b[0]; ++i)
b[i] = strb[b[0] - i] - '0';
for (reg int i = 1; i <= a[0]; ++i)
for (reg int j = 1; j <= b[0]; ++j)
ans[i + j - 1] += a[i] * b[j];
len = a[0] + b[0];
for (reg int i = 1; i <= len; ++i)
{
ans[i + 1] += ans[i] / 10;
ans[i] %= 10;
}
for (reg int i = len; i >= 1; --i)
if (ans[i] != 0)
{
len = i;
break;
}
for (reg int i = len; i >= 1; --i)
cout << ans[i];
return 0;
}
by Laegrande @ 2023-02-15 08:06:35
666
by denghuolanshan_1004 @ 2023-02-15 17:56:03
@fengziyi
用万能头不好吗(((