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\n");
 9         else
10             printf("no\n");
11     }
12     return 0;
13 }

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




相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-24
  • 2021-06-08
  • 2021-10-06
  • 2021-07-12
猜你喜欢
  • 2022-12-23
  • 2021-05-30
  • 2021-06-23
  • 2021-08-21
  • 2021-06-06
  • 2021-07-03
  • 2021-08-08
相关资源
相似解决方案