huangtianzeC @ 2024-01-22 20:39:10
#include<iostream>
#include<cstring>
using namespace std;
string che(string s1,string s2){
int a[1005]={},b[1005]={},ans[3005]={};
string s3="";
int lena=s1.size(),lenb=s2.size();
for(int i=0;i<lena;++i) a[i]=s1[lena-i-1]-'0';
for(int i=0;i<lenb;++i) b[i]=s2[lenb-i-1]-'0';
int lenc=lena+lenb;
for(int i=0;i<lena;++i){
for(int j=0;j<lenb;++j){
ans[i+j]+=a[i]*b[j];
ans[i+j+1]+=ans[i+j]/10;
ans[i+j]=ans[i+j]%10;
}
}
int t=lenc;
while(ans[t]==0&&t>0) t--;
for(int i=t;i>=0;--i) s3+=ans[i]+'0';
return s3;
}
string jia(string a1,string b1){
int a[1005]={},b[1005]={},c[3005]={};
string c1="";
int lena=a1.size();
int lenb=b1.size();
for(int i=0;i<lena;++i) a[i]=a1[lena-1-i]-'0';
for(int i=0;i<lenb;++i) b[i]=b1[lenb-1-i]-'0';
int lenc=max(lena,lenb);
for(int i=0;i<lenc;++i){
c[i]+=a[i]+b[i];
if(c[i]>9){
c[i+1]++;
c[i]=c[i]%10;
}
}
if(c[lenc]) c1+=c[lenc]+'0';
for(int i=lenc-1;i>=0;--i) c1+=c[i]+'0';
return c1;
}
int main(){
string s1,ans="0";
cin>>s1;
if(s1.size()==1) s1='0'+s1;
int n=(s1[0]-'0')*10+(s1[1]-'0');
for(int i=1;i<=n;++i){
string tmp="1";
for(int j=1;j<=i;++j){
string s3;
s3+=(j/10%10+'0');
s3+=(j%10+'0');
if(s3[0]=='0') s3=s3[1];
tmp=che(tmp,s3);
}
ans=jia(ans,tmp);
}
cout<<ans;
return 0;
}
by Y_QWQ_Y @ 2024-01-22 20:48:43
@huangtianzeC Python自带高精度。。。。。。
n = int (input ())
s = 1;
ans = 0;
for i in range (1, n + 1, 1):
s *= i;
ans += s;
print (ans)
by huangtianzeC @ 2024-01-22 20:51:58
@Y_QWQ_Y 你用C++搞一下吧,我不玩PY
by Y_QWQ_Y @ 2024-01-22 20:53:52
@Y_QWQ_Y c++高精度有问题,是Python救了我!
(逃
by zza_LG @ 2024-01-22 21:04:51
高精函数差不多,就main()
函数里面少几行你19行,我10行。
#include<bits/stdc++.h>
using namespace std;
string jia(string a,string b){
int x[10005]={},y[10005]={},z[10005]={};
string c="";
for(int i=a.size()-1,j=1;i>=0;i--,j++)x[j]=a[i]-'0';
for(int i=b.size()-1,j=1;i>=0;i--,j++)y[j]=b[i]-'0';
int l=max(a.size(),b.size());
for(int i=1;i<=l;i++){
z[i]+=x[i]+y[i];
z[i+1]+=z[i]/10;
z[i]%=10;
}
if(z[l+1]>0)l++;
for(int i=l;i>=1;i--)c=c+char(z[i]+'0');
return c;
}
string cheng(string a,string b){
int x[10005]={},y[10005]={},z[20005]={};
string c="";
for(int i=a.size()-1,j=1;i>=0;i--,j++)x[j]=a[i]-'0';
for(int i=b.size()-1,j=1;i>=0;i--,j++)y[j]=b[i]-'0';
for(int i=1;i<=a.size();i++){
for(int j=1;j<=b.size();j++){
z[i+j-1]+=x[i]*y[j];
z[i+j]+=z[i+j-1]/10;
z[i+j-1]%=10;
}
}
int l=a.size()+b.size();
if(z[l]==0&&l!=1)l--;
for(int i=l;i>=1;i--)c=c+char(z[i]+'0');
return c;
}
int n;
string a="1",s;
int main(){
cin>>n;
for(int h=1;h<=n;h++){
a="1";
for(int i=1;i<=h;i++)a=cheng(a,to_string(i));
s=jia(s,a);
}
cout<<s;
return 0;
}
@huangtianzeC
这题解能通过审核!?
看完后自己好好思考,最好不要抄代码在题解上。
by I_like_play_eggy @ 2024-01-31 11:45:03
@Y_QWQ_Y Python不用分号。
n,s,ans=int(input()),1,0
for i in range(1,n+1,1):
s*=i
ans+=s
print(ans)
by return_second @ 2024-03-09 20:19:18
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct Big
{
int len,a[150];
Big(int x=0)
{
memset(a,0,sizeof(a));
for(len=1;x;len++)
{
a[len]=x%10;
x/=10;
}
len--;
}
void clear(int L)
{
len=L;
for(int i=1;i<=len;i++)
{
a[i+1]+=a[i]/10;
a[i]%=10;
}
while(!a[len])
len--;
}
void print()
{
for(int i=max(len,1);i>=1;i--)
printf("%d",a[i]);
}
int &operator[](int i)
{
return a[i];
}
};
Big operator+(Big a,Big b)
{
Big c;
int len=max(a.len,b.len);
for(int i=1;i<=len;i++)
c[i]+=a[i]+b[i];
c.clear(len+1);
return c;
}
Big operator*(Big a,int b)
{
Big c;
int len=a.len;
for(int i=1;i<=len;i++)
c[i]=a[i]*b;
c.clear(len+11);
return c;
}
int main()
{
int n;
Big sum(0),cnt(1);
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
cnt=cnt*i;
//cnt.print();
//puts("");
sum=sum+cnt;
}
sum.print();
return 0;
}