Fibonacci Again

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


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

题意:

题意就是问你第n个斐波那契数能不能被3整除。如果是用longlong数组储存计算结果依次递推的话,很容易就会爆掉,因为这个的变化类似于2^n,所以用不了多少就会爆掉longlong的,所以不妨打表观察一下得,2,6,10…成等差数列。所以N-2是4的倍数的都是。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;

long long f[1000000+5]; //longlong类型会爆掉,因为指数是类似2^n指数增长 

int main()
{
    f[0]=7;
    f[1]=11;
    int t;
    while(~scanf("%d",&t))
    {
        if((t-2)%4==0){
            cout<<"yes"<<endl;
            continue;
        }
        else {
            cout<<"no"<<endl;
            continue;
        }
    }
    return 0;    
}