castal_ @ 2023-01-21 22:36:04
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
int a[N],b[N],c[N];
int main()
{
int n,x=1;
cin>>n;
a[1] = 1, b[1] = 2;
if(n < 3)
{
cout<<n;
return 0;
}
for(int i = 3;i <= n; ++i)
{
for(int j = 1;j <= x; ++j)
{
c[j] = a[j] + b[j];
c[j + 1] += c[j] / 10;
c[j] %= 10;
}
if(c[x+1] > 0) x++;
for(int w = 1;w <= x; ++w) a[w] = b[w];
for(int w = 1;w <= x; ++w) b[w] = c[w];
}
for(int i = x; i >0; i--) cout<<b[i];
return 0;
}
by bamboo12345 @ 2023-01-21 22:56:40
@castal_ 进位是假的
by castal_ @ 2023-01-21 23:28:41
@bamboo123
什么意思哦?
by bamboo12345 @ 2023-01-21 23:32:49
@castal_ 你思考一下如果有一个加法进位你的c会不会错
by castal_ @ 2023-01-21 23:33:26
@bamboo123 对,进位的时候就会错
by castal_ @ 2023-01-21 23:34:08
@bamboo123 那个进位的地方应该怎么写呢?
by bamboo12345 @ 2023-01-21 23:35:24
@castal_ 就是说你可以用完一次清零一次,把c数组设为a+b时调为+=就行了
by castal_ @ 2023-01-21 23:38:14
@bamboo123
好的好的,AC了,感谢感谢
by castal_ @ 2023-01-21 23:38:37
@bamboo123
新年快乐,大佬
by bamboo12345 @ 2023-01-21 23:40:37
@castal_ 新年快乐,不要卷了去看春晚去
by castal_ @ 2023-01-21 23:45:16
@bamboo123
好的好的,这就去看了