N很大情况下的Fibonacci前四位-HDU1568(重要)
程序员文章站
2024-03-19 19:05:34
...
http://acm.hdu.edu.cn/showproblem.php?pid=1568
参考博客:http://www.cnblogs.com/Yu2012/archive/2011/10/09/2199156.html (很重要)
http://blog.csdn.net/lvshubao1314/article/details/38013897
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int mod=10000;
int a[25]={0,1,1};
int main()
{
for(int i=3;i<=20;i++)
a[i]=a[i-1]+a[i-2];
int s;
while(~scanf("%d",&s))
{
if(s<=20)
cout<<a[s]<<endl;
else{
double f=(1.0+sqrt(5.0))/2.0;
double m=(-0.5)*log(5)/log(10)+s*log(f)/log(10);
m=m-floor(m);
double q=pow(10,m);
while(q<1000)
{
q=q*10;
}
cout<<(int)q<<endl;
}
}
return 0;
}