游客 Signup | Login
中文 | En

2198 - 最简单的难题

我们定义F(0) = 7, F(1) = 11, F(n) = F(n - 1) + F(n - 2)

Input

输入数据包括多行,每行一个个数字nn < 1,000,000

Output

如果F(n)能被3整除就输出yes,不能则输出no

Examples

Input

0
1
2
3
4
5

Output

no
no
yes
no
no
no

Solution C

#include<stdio.h>
int main()
{
	int n, i, a, b, c;
	while(scanf("%d",&n) != EOF)
	{
		a = 1;
		b = 2;
		c = 3;
		for(i = 2; i <= n; i++)
		{
			c = (a + b) % 3;
			a = b;
			b = c;
		}
		if(c == 0)
			puts("yes");
		else
			puts("no");
		
	}
	
	return 0;	
}

Solution C++

#include <cstdio>
const int V = 1000000 + 50;
int num[V];
int main() {
    int i, n;
    num[0] = 1;
    num[1] = 2;
    for(i = 2; i < V; ++i)
        num[i] = (num[i - 1] + num[i - 2]) % 3;
    while(~scanf("%d", &n))
        printf("%s\n", num[n] ? "no" : "yes");
}
Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题