HDU-1021 Fibonacci Again

简介: HDU-1021 Fibonacci Again

题目:

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

解析:

1. 分析题目,既然是mod 3所以很有可能是循环的

2. 于是进行打表(打表真的是个好东西),发现最后以为的数字具有变化周期,周期为12,打表结果如下图所示

#include
int main(){
    int a[100]={7,11};
    for(int i=2;i<12;i++)
    {
        a[i]=a[i-1]+a[i-2];
    }
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        if(a[n%12]%3!=0)
        {
            printf("no\n");
        }
        else
        {
            printf("yes\n");
        }
    }
return 0;
}


相关文章
|
算法
|
存储 人工智能 Java
HDU 1250 Hat&#39;s Fibonacci
Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11104    Accepted Submission(...
781 0
|
Java
HDU 1021 Fibonacci Again
Fibonacci Again Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 58267    Accepted Submission(...
906 0
|
机器学习/深度学习 Java
【HDU 4786 Fibonacci Tree】最小生成树
一个由n个顶点m条边(可能有重边)构成的无向图(可能不连通),每条边的权值不是0就是1。 给出n、m和每条边的权值,问是否存在生成树,其边权值和为fibonacci数集合{1,2,3,5,8...}中的一个。
1072 0