题目

Description

Fibonacci 数列的另一种形式
F(0)=7, F(1)=11 F(n)=F(n-1)+F(n-2) (n>=2)

Input

包括多行,每行有一个整数n(n<1,00,000),当n<0时表示输入结束

Output

对应输入的n,若序列的第n项能被3整数,则输出Yes,否则输出No.

Sample Input

0
1
2
3
4
5
-1

Sample Output

No
No
Yes
No
No
No

题解

递推+记忆化搜索即可

代码

/*
By:OhYee
Github:OhYee
HomePage:http://www.oyohyee.com
Email:oyohyee@oyohyee.com
Blog:http://www.cnblogs.com/ohyee/
 
かしこいかわいい?
エリーチカ!
要写出来Хорошо的代码哦~
*/
 
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
using namespace std;
 
//DEBUG MODE
#define debug 0
 
//循环
#define REP(n) for(int o=0;o<n;o++)
 
const int maxn = 100005;
int f[maxn];
int F(int n) {
    if(f[n] == -1) {
         f[n] = F(n - 1) + F(n - 2);
    }
    return f[n];
}
 
bool Do() {
    int n;
    if(scanf("%d",&n),n<0)
        return false;
 
    //printf("%d %d ",n,F(n));
    printf((F(n) % 3) == 0 ? "Yes\n" : "No\n");
 
    return true;
}
 
int main() {
    memset(f,-1,sizeof(f));
 
    f[0] = 7;
    f[1] = 11;
 
    while(Do());
    return 0;
}