hdu 1021 Fibonacci Again

来源:互联网 发布:cf刷经验软件 编辑:程序博客网 时间:2024/06/08 06:51

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

012345
 

Sample Output

nonoyesnonono 这题如果直接算会超时可以多打印几组数据出来就可以看到规律了根据规律先对数列的各项%3求余就不会超时了
#include <stdio.h>#include <string.h>#define N 1000010int num[N];int main(){int n;while (scanf("%d", &n) != EOF) {memset(num, 0, sizeof(num));num[0] = 7 % 3, num[1] = 11 % 3;for (int i = 2; i < N; i++)num[i] = (num[i-1] + num[i - 2]) % 3;if (num[n] % 3 == 0)printf("yes\n");elseprintf("no\n");}return 0;}



0 0