hdoj_1568_code

 1 #include <stdio.h>
 2 #include <math.h>
 3 
 4 void main()
 5 {
 6     int a[21];
 7     int n,i;
 8     double p,sum;
 9     a[0] = 0; a[1] = 1;
10     for(i = 2; i <= 20; i ++)
11         a[i] = a[i-1] + a[i-2];
12     while(scanf("%d",&n)!= EOF)
13     {
14         if(n <= 20)
15         {
16             printf("%d\n",a[n]);
17             continue;
18         }
19         else{
20              sum = log10(1.0/sqrt(5))+n*log10((1 + sqrt(5))/2); //利用公式,并且省去了取对数时候趋于零的那部分。
21             sum = sum - (int)sum;
22             p = pow(10,sum);
23             while(p < 1000)//至于为什么这样呢,相当于移位操作
24                 p *=10;
25             printf("%d\n",(int)p);//输出时候取整。
26         }
27 
28     }
29 }

 

posted @ 2012-04-17 18:14  南柯南  阅读(141)  评论(0编辑  收藏  举报