Chinese_Dragon @ 2023-10-07 17:23:40
除#6外全无输出!
#include<bits/stdc++.h>
using namespace std;
string x,y,m;
int a[10000],b[100000],ans[100000],c;
string high_plus(string x,string y);
int main()
{
int n;
x=y="1";
cin>>n;
for (int i=1;i<=n-2;i++)
{
high_plus(x,y);
x=y;
y=m;
}
cout<<y;
return 0;
}
string high_plus(string x,string y)
{
for (int i=x.size()-1;i>=0;i--)
{
a[x.size()-i]=x[i]-'0';
}
for (int i=y.size()-1;i>=0;i--)
{
b[y.size()-i]=y[i]-'0';
}
for (int i=1;i<=max(x.size(),y.size());i++)
{
ans[i]=a[i]+b[i]+c;
c=0;
if (ans[i]>=10)
{
c=1;
ans[i]%=10;
}
}
if (c!=0)
{
ans[max(x.size(),y.size())+1]=c;
for (int i=max(x.size(),y.size())+1;i>=1;i--)
{
m[max(x.size(),y.size())+1-i]=char(ans[i]+'0');
}
}
else
{
for (int i=max(x.size(),y.size());i>=1;i--)
{
m[max(x.size(),y.size())-i]=char(ans[i]+'0');
}
}
return m;
}
by sakura_erii @ 2023-10-09 09:53:13
#include<iostream>
using namespace std;
int f[5010][2010]; //存储每一项都是高精度数的递推序列
int main()
{
int n;
cin>>n;
f[0][0] = 1,f[0][1] = 0; //第0项,高精度是0(过输入0的测试点)
f[1][0] = f[1][1] = 1; //第1项,高精度数1
f[2][0] = 1,f[2][1] = 2; //第2项,高精度数2
for(int i=3;i<=n;i++){
int x = 0;
for(int j=1;j<=f[i-1][0] || j<=f[i-2][0];j++){
f[i][0]++;
f[i][j] = f[i-1][j] + f[i-2][j] + x;
if(f[i][j]>=10) f[i][j] -= 10,x = 1;
else x = 0;
}
if(x) f[i][++f[i][0]] = x;
}
for(int i=f[n][0];i>=1;i--) cout<<f[n][i];
return 0;
}