您的位置:首页 > 其它

N很大情况下的Fibonacci前四位-HDU1568(重要)

2017-07-16 17:45 471 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: