1021 Fibonacci Again
阿新 • • 發佈:2019-02-12
nProblem Description
nSample input:
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).
Print the word "yes" if 3 divideevenly into F(n).
Print the word "no" if not.
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; }