hdu_1021_Fibonacci Again_201310232237

 

Fibonacci Again

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 30227    Accepted Submission(s): 14685

Problem Description
There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).
 
Input
Input consists of a sequence of lines, each containing an integer n. (n < 1,000,000).
 
Output
Print the word "yes" if 3 divide evenly into F(n).
Print the word "no" if not.
 
Sample Input
0
1
2
3
4
5
 
Sample Output
no
no
yes
no
no
no
 
Author
Leojay
 
 1 #include <stdio.h>
 2 
 3 int main()
 4 {
 5     int f[20];
 6     int n;
 7     while(scanf("%d",&n)!=EOF)
 8     {
 9         int i,xh;
10         f[0]=7%3;
11         f[1]=11%3;
12         for(i=2;i<20;i++)
13         {
14             f[i]=(f[i-1]+f[i-2])%3;
15             if(f[i]==2&&f[i-1]==1)
16             break;
17         }
18         xh=i-1;
19         n=n%xh;
20         if(f[n]==0)
21         printf("yes\n");
22         else
23         printf("no\n");
24     }
25     return 0;
26 }

思路详见hdu_1005  这两题类似

 
posted @ 2013-10-23 22:53  龙腾四海365  阅读(106)  评论(0编辑  收藏  举报