1. 程式人生 > >1021 Fibonacci Again

1021 Fibonacci Again

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;
}