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

题目意思:给你一种新定义的斐波那契数列,问其第n项是否能被3整除。

唉啊,这个题有点坑了,我当时没有看出这道题的规律直接遍历判断是否符合情况,结果直接给我来了一个超时,当时脑子也瓦特了,
不能静下心好好分析一下,找找规律。
我们可以找找前几个斐波那契数的规律
F[0]=7,F[1]=11,F[2]=18,F[3]=29,F[4]=47,F[5]=76,F[6]=123.......
我们可以看到从第二个斐波那契数开始每隔4个就会出现一个符合情况的


上代码:
 1 #include<stdio.h>
 2 int main()
 3 {
 4     int n;
 5     while(scanf("%d",&n)!=EOF)
 6     {
 7         if(n%4==2)
 8             printf("yes
");
 9         else
10             printf("no
");
11     }
12     return 0;
13 }

代码倒是简单。。。。。。。




原文地址:https://www.cnblogs.com/wkfvawl/p/8710457.html