0 1 2 3 4 5 35 36 37 38 39 40
0 1 1 2 3 5 9227 1493 2415 3908 6324 1023
此图片配合上一篇文章看 口味更加,,这种方法已经熟练掌握了;
变形公式很重要!!!!!!!注意极限很重要!!!!!!(当然用快速幂去解也可以的拉。。)
懂得常系数线性非齐次递推关系也很重要!!熟练用高中log知识也很重要!!!
总结就是 数学很重要!!!
代码要预处理好小于4位数的情况 而且从上面的图片看出 只有n>=20时 误差不会太大
#include<stdio.h> #include<math.h> int K[21]; int main() { freopen("a.in","r",stdin); freopen("a.out","w",stdout); int n,i; double t1,t2,t3,ans; K[1]=1;K[2]=1; for(i=3;i<=20;i++) K[i]=K[i-1]+K[i-2]; while(scanf("%d",&n)!=EOF) { if(n<=20) {printf("%d\n",K[n]);continue;} t1=-0.5*log10((5.0)); t2=log10((1+sqrt(5))/2.0); t3=t1+n*t2; t3=t3-(int)t3; ans=pow(10.0,t3); ans=ans+10e-8; while(ans<=1000) ans=ans*10; printf("%d\n",(int)ans); } return 0; }