Fibonacci Again HDU

来源:互联网 发布:exe打包软件 编辑:程序博客网 时间:2024/06/05 21:01
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
012345
Sample Output
nonoyesnonono



思路  若暴力求解,一定会超出longlong 的范围,求一个规律。

 

从图可得  8个是一个循环。


#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int main(){    int m;    int f[8]={1,2,0,2,2,1,0,1};    while(~scanf("%d",&m))    {        int n=f[m%8];        if(n!=0)            printf("no\n");        else            printf("yes\n");    }    return 0;}