# [1021]：Fibonacci Again

228人阅读 评论(0)

Fibonacci Again

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 46300 Accepted Submission(s): 22077

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<stdio.h>
#define F0 7
#define F1 11//题意给出的F(0) F(1)

int num;
int main()
{
while(scanf("%d", &num)!=EOF){
int a = F0%3, b = F1%3, n=2;
if(num==0 || num==1){
printf("no\n");
}
else{
for(; n<=num; n++){
int left = (a+b)%3;//①这一部分解释如图一
a = b;
b = left;
if(left%3==0 && n==num){
printf("yes\n");
}
else if(left%3!=0 && n==num){
printf("no\n");
}
}
}
}
return 0;
}

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：70384次
• 积分：2782
• 等级：
• 排名：第14884名
• 原创：217篇
• 转载：0篇
• 译文：0篇
• 评论：3条
阅读排行
最新评论