HDOJ 1021 Fibonacci Again

sa
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
//
//  main.cpp
//  Fibonacci Again
//
//  Created by 张嘉韬 on 16/3/9.
//  Copyright © 2016年 张嘉韬. All rights reserved.
//

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int a[10]={1,2,0,2,2,1,0,1};
int main(int argc, const char * argv[]) {
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        //cout<<"("<<n<<")";
        int temp=n%8;
        if(a[temp]==0) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}

nono
总结:
思路和之前  

HDOJ 1005 Number Sequence完全一致,当前的数fn只由前两位fn-1和fn-2所确定,并且是否能被三整除也只与前两位mod3有关,由于mod3 只有 0 1 2这三种情况,所以连续的两位只有9种情况,而且一旦这9种中的任意一种重复出现,之后便会进行循环,所以我们很自然的就猜想会出现循环,沿着这个思路我们手工推算就很容易发现规律,之后打表就能完成

你可能感兴趣的:(HDOJ 1021 Fibonacci Again)