Fibonacci Again

来源:互联网 发布:深入浅出node.js 微盘 编辑:程序博客网 时间:2024/05/18 20:37

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.

#include <iostream>using namespace std;int f (int n);int main (){    int count = 0, num;    while(count <=3)    {        cin >> num;        if(f(num)%3 == 0)            cout << "YES" << endl;        else            cout << "NO" << endl;        count ++;    }    return 0;}int f (int n){    switch(n)    {        case 0: return 7; break;        case 1: return 11; break;    }    return f(n-1)+f(n-2);}