您的位置:首页 > 大数据 > 人工智能

1021 Fibonacci Again

2016-07-28 22:53 567 查看
nProblem Description
    There are another kind of Fibonaccinumbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).

nInput
    Input consists of a sequence of lines, eachcontaining an integer n. (n < 1,000,000).

nOutput
    Print the word "yes" if 3 divideevenly into F(n).

Print the word "no" if not.

nSample input:

     0 1 2 3 4 5 6

n
nSample output:
     no no yes no no no yes

#include<iostream>
#include<stdio.h>

using namespace std;

int Fibonacci(int n)
{
if(n<0)
return -1;
else if(n ==0)
return 7;
else if(n ==1)
return 11;
else
return Fibonacci(n-1)+Fibonacci(n-2);
}

int main(void)
{
int n;
while(scanf("%d",&n) != EOF)
{
if(Fibonacci(n)%3 == 0)
printf("yes ");
else
printf("no ");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  斐波那契数列