c初学者,一道小题不知道哪里错了,走过路过的大神顺便看一眼啊。。。
题目是这这样的:
There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).
InputInput: consists of a sequence of lines, each containing an integer n. (n < 1,000,000,000).
OutputPrint: the word "yes" if 3 divide evenly into F(n). Print the word "no" if not.
我的代码是这样的:
#include<stdio.h>
int main ()
{
int n,f0=7,f1=11,i,flag;
while(scanf("%d",&n)!=EOF)
{
for(i=1;i<=n/2;i++)
{
f0=f0+f1;
f1=f0+f1;
}
if(n%2==0)
{
if(f0%3==0)
flag=1;
else
flag=0;
}
else
{
if(f1%3==0)
flag=1;
else
flag=0;
}
if(flag==1)
printf("yes\n");
else
printf("no\n");
f0=7;f1=11;
}
return 0;
}
[解决办法]
3 7 11...满足Yes,所以if((n - 3) % 4 == 0) printf("Yes").