huyike_2012 @ 2024-09-23 16:41:07
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long a[55];
int n;
cin >> n;
a[1] = 1;
a[2] = 2;
for (int i = 3; i <= n ; i ++ )
{
a[i] = a[i - 1] + a[i - 2] ;
}
cout << a[n] << endl;
return 0;
}
by HEzzz @ 2024-09-23 16:50:43
要高精度哇
by IAKIOI___ @ 2024-09-23 20:18:02
@huyike_2012
#include <bits/stdc++.h>
using namespace std;
int n, len = 1, a[5005][5005];
void work(int x)
{
int i;
for (i = 1; i <= len; i++)
{
a[x][i] = a[x - 1][i] + a[x - 2][i];
}
for (i = 1; i <= len; i++)
{
if (a[x][i] >= 10)
{
a[x][i + 1] += a[x][i] / 10;
a[x][i] %= 10;
if (a[x][len + 1] > 0) len++;
}
}
}
int main()
{
int i;
cin >> n;
a[1][1] = 1, a[2][1] = 2;
for (i = 3; i <= n; i++)
{
work(i);
}
for (i = len; i >= 1; i--)
{
cout << a[n][i];
}
return 0;
}
by huyike_2012 @ 2024-09-24 19:50:03
@HEzzz @IAKIOI___ thx已AC