FatMouse' Trade

题目

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

参考代码

#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
int a;
while(scanf("%d",&a))
{
if(a%4==2)
printf("yes\n");
else printf("no\n");
}
//太无语了。。。。
}

错误示例

#include
#include<stdio.h>
using namespace std;
const int N=1000000;
int main()
   {
int F[N],f0=0,f1=1,fn=2,a;
F[0]=7;
   F[1]=11;
for(int i=0;i<N-3;i++)
{
F[fn]=F[f0]+F[f1];
   fn++;f0++;f1++;
}
   while(scanf("%d",&a)!=EOF)
{
if(F[a]%3)
printf("no");
else printf("no");
}
}

在这道题目里如果按照求Fibonacci每一项的思路来做,就会超出限制,因此,只能通过找规律来ac。说实话这个规律我也不知道是为什么。。。。

posted @ 2016-02-15 23:31  Pic  阅读(148)  评论(0编辑  收藏  举报