1-S-Fibonacci Again
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.
Print the word "no" if not.
Sample Input
0
1
2
3
4
5
Sample Output
no no yes no no no
1 /* 2 #include<stdio.h> 3 long fibonacci(long n); 4 int main() 5 { 6 long n; 7 while(scanf("%ld",&n)!=EOF&&n<1000000&&n>=0) 8 { 9 //printf("%ld\n",fibonacci(n)); 10 if(fibonacci(n)%3==0)printf("yes\n"); 11 else printf("no\n"); 12 } 13 return 0; 14 } 15 16 long fibonacci(long n) 17 { 18 if(n==0) return 7; 19 else if(n==1) return 11; 20 else return fibonacci(n-1)+fibonacci(n-2); 21 } 22 23 24 25 26 //以上是超时代码,以下是百度来的正确答案 27 #include<stdio.h> 28 int main() 29 { 30 int n; 31 while (scanf("%d",&n)==1) 32 if(n%8==2||n%8==6) 33 printf("yes\n"); 34 else printf("no\n"); 35 return 0; 36 } 37 */ 38 39 //以下是我明白了用递归会超时的真理后按照百度自己又写了一遍 40 41 #include<stdio.h> 42 int main() 43 { 44 int n; 45 while(scanf("%d",&n)!=EOF) 46 { 47 if(n%8==2||n%8==6)//但我还是不懂为什么要这样取余!!!!!!!!! 48 //终于懂了,为什么这样取余 49 /* 50 首先一个个找规律,发现 51 f(0)=F(0)%3=7%3=1 52 f(1)=F(1)%3=11%3=2 53 f(2)=F(2)%3=18%3=0 54 f(3)=F(3)%3=29%3=2 55 f(4)=F(4)%3=47%3=1 56 f(5)=F(5)%3=76%3=1 57 f(6)=F(6)%3=123%3=0 58 f(7)=F(7)%3=199%3=1 59 f(8)=F(8)%3=322%3=1 60 f(9)=F(9)%3=521%3=2 61 f(10)=F(10)%3=843%3=0 62 f(11)=F(11)%3=1364%3=2 63 f(12)=F(12)%3=2207%3=2//算错了不想算了 64 65 总之这个Fibonacci数列对3取余后余数8个一组循环 66 然后如果输入一个数n它对8取余余数为2和6的都是所求答案! 67 */ 68 printf("yes\n");//presentation error!=v= 又忘记回车转义字符了 69 else printf("no\n"); 70 } 71 return 0; 72 }
浙公网安备 33010602011771号