Problem 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
思路:这道题要找规律,而不是用斐波那契数列,因为题上的数据很大,100万,代码执行不了,因此就需要找规律(一般数据大的时候都有规律的)。假如我们令F(0)=1,F(1)=2,m=(F(n-1)+F(n-2))(mod3)那么规律是这样的:
n 0 1 2 3 4 5 6 7 8 9 10
F(n) 1 2 3 5 8 13 21 34 55 89 144
m 1 2 0 2 2 1 0 1 1 2 0
则由上面可以看出2,6,10能够被3整出,以此类推,下面能够被3整除的n还有14,18,22,26.......即n%4=2的F(n)能够被3整除。
My DaiMa:
#include<iostream>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
if(n%4==2)
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
return 0;
}