#include <cstdio>
#include <cmath>
#include <iostream>
using namespace std;
const int maxn=1000+5;
long long fib[maxn]={1, 1};
void fibonacci(int n)
{
for(int i=2;i<=n;i++)
{
fib[i] = fib[i-1] + fib[i-2];
cout<<i<<endl;
cout<<fib[i]<<endl;
if(fib[i]<0) break;
}
}
int main()
{
//预处理生成
fibonacci(1000);
int n=0;
while(scanf("%d", &n)==1)
{
printf("%lld ", fib[n-1]);
}
return 0;
}
输出:
91
7540113804746346429
92
-6246583658587674878
92项就溢出了,要采用高精度算法。