首页 > 代码库 > Fibonacci Again
Fibonacci Again
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
1 #include <stdio.h> 2 3 int calculate_Fn(int number); 4 5 int main(){ 6 int number; 7 8 while((scanf("%d",&number))!=EOF){ 9 if(calculate_Fn(number)==0)10 printf("yes\n");11 12 else13 printf("no\n");14 }15 return 0;16 }17 18 int calculate_Fn(int number){19 int i;20 int result;21 int temp;22 int a=7;23 int b=11;24 25 if(number==0)26 return a;27 28 else if(number==1)29 return b;30 31 for(i=2;i<=number;i++){32 result=(a%3+b%3)%3;33 34 temp=b;35 b=result;36 a=temp;37 }38 39 return result;40 }
Fibonacci Again
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。