题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=1021
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
Hint
题意
问这个特殊的Fibonacci 数列里,对应的那个数,是否能被3整除。
题解
7 11 18 29 47 76 123…
1 2 0 2 2 1 0…
某一个数的余数等于前两个数的余数之和在对3求余(如76的余数=(2+2)/3),可以dp,也可以找规律……话说dp好像真的就是中规律
代码
#include<stdio.h>
int main()
{
long n;
while(scanf("%ld",&n) != EOF)
if (n%8==2 || n%8==6)
printf("yes\n");
else
printf("no\n");
return 0;
}