Whl0924 @ 2024-06-13 13:38:06
#include<bits/stdc++.h>
using namespace std;
int n,f[1]=0,f[2]=0;
int main(){
cin>>n;
f[1]=Bigint(1);
f[2]=Bigint(2);
for(int i=3;i<=n;i++)
f[i]=f[i-2]+f[i-1];
f.print();
return 0;
}
by Whl0924 @ 2024-06-13 13:38:45
求助啊!
by 迟暮天复明 @ 2024-06-13 14:10:50
不是哥们你这Bigint是啥
by gaoliuchang1101 @ 2024-06-16 12:52:24
@Whl0924 没设BigInt
const int N=505;
struct BigInt{
int a[N],la;
void init (int x)
{
a[1]=x;
la=1;
}
void add(BigInt A,BigInt B){
la=max(A.la,B.la);
for(int i=1;i<=la;i++)
{
a[i]=A.a[i]+B.a[i];
}
for(int i=1;i<=la;i++){
a[i+1]+=a[i]/10;
a[i]=a[i]%10;
}
if(a[la+1]>0)
{
la++;
}
}
void print(){
for(int i=la;i>=1;i--)
{
cout<<a[i];
}
}
}f[N];
这么设。
by gaoliuchang1101 @ 2024-06-16 13:10:46
主函数:int main()
{
f[1].init(1);
f[2].init(2);
cin>>n;
for(int i=3;i<=n;i++)
f[i].add(f[i-1],f[i-2]);
f[n].print();
return 0;
}