【问题描述】There are another kind of Fibonacci number:F(0)=7,F(1)=11,F(n)=F(n-1)+F(n-2) (n>=2).
【输入形式】Input an interger n.(n<1000000)
【输出形式】Print the word "yes" if 3 divide evenly into F(n).Print the word "no" if not.
【样例输入】5
【样例输出】no
【输入形式】Input an interger n.(n<1000000)
【输出形式】Print the word "yes" if 3 divide evenly into F(n).Print the word "no" if not.
【样例输入】5
【样例输出】no
【样例说明】if input 5,print the word"no".
题目大概意思就是,给一个数n,判断斐波那契数列第n个数是否能整除3,(n小于1000000)。
能整除输出yes,不能则输出no。
#include<stdio.h>
int main()
{
int i;
while(scanf("%d",&i)!=EOF)
{
if((i-2)%4==0)
printf("yes\n");
else
printf("no\n");
}
return 0;
}
这道题其实是一道找规律的题,由于n小于1000000,当n接近百万时,此时的斐波那契数将变得非常大,long long int 都无法存储,所以由此想到需要去寻找规律,而会发现其实规律很简单,当i减去2,对4取模后等于0,则能满足,例如i = 2时,斐波那契数 F[2] = F[0] + F[1],等于18,当i等于6时,F[6] = F[5]+F[4]; 其中F[5] = F[4] + F[3] 等于76,F[4] = F[3] + F[2] 等于47;所以F[6] 等于123,也能整除3;同样F[8]等i-2取模4 == 0的数,都能满足条件。