| |||
来源 | 计算概论助教marcus(罗老师班) | ||
描述 | |||
我们新定义一种Fibonacci数列:F(0)=7, F(1)=11, 递推式为F(n)=F(n-1)+F(n-2) (n>=2) | |||
关于输入 | |||
测试数据包含很多行,每行包含一个整数n (n>=0 且 n<1,000,000),我们以1,000,001结束输入 | |||
关于输出 | |||
如果F(n)能被3整除,则输出"yes",否则输出"no"。每个输出结果后只需一次换行。 | |||
例子输入 | |||
0
1
2
3
4
5
1000001 | |||
例子输出 | |||
no no yes no no no | |||
提示 | |||
手工模拟几组n,例如: n=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,… 算出余数F(n)%3依次为: 1,2,0,2,2,1,0,1,1,2,0,2,2,1,0,1,1,2,0,2,2,1,0,1,… |
#include<stdio.h>
int newFeibonacci(int i){
int marcus;
if(i==0)marcus=7;
else if(i==1)marcus=11;
else marcus=newFeibonacci(i-1)+newFeibonacci(i-2);
return marcus;
}
int main(){
int temp;
int marcus;
scanf("%d",&temp);
do{
marcus=newFeibonacci(temp);
/*printf("%d",marcus);*/
if(marcus%3){
printf("no");
}
else printf("yes");
scanf("%d",&temp);
}
while(temp>=0&&temp<1000000);
return 0;
}