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;
}


相关文章
HDOJ(HDU) 2504 又见GCD(利用最大公约数反推)
HDOJ(HDU) 2504 又见GCD(利用最大公约数反推)
84 0
HDOJ(HDU) 2503 a/b + c/d(最大公约数问题)
HDOJ(HDU) 2503 a/b + c/d(最大公约数问题)
111 0
|
机器学习/深度学习
POJ 1775 (ZOJ 2358) Sum of Factorials
POJ 1775 (ZOJ 2358) Sum of Factorials
122 0
|
机器学习/深度学习 Java
|
人工智能 机器学习/深度学习
POJ 1775 (ZOJ 2358) Sum of Factorials
Description John von Neumann, b. Dec. 28, 1903, d. Feb. 8, 1957, was a Hungarian-American mathematician who made important contributions t...
1113 0
【HDU 4786 Fibonacci Tree】最小生成树
一个由n个顶点m条边(可能有重边)构成的无向图(可能不连通),每条边的权值不是0就是1。 给出n、m和每条边的权值,问是否存在生成树,其边权值和为fibonacci数集合{1,2,3,5,8...}中的一个。
1028 0