Description
Input consists of a sequence of lines, each containing an integer n. (n < 1,000,000,000).
Input
Print the word "yes" if 3 divide evenly into F(n). Print the word "no" if not.
Output
1
2
3
4
5
6
7
|
0
1
2
3
4
5
|
Sample Input
1
2
3
4
5
6
|
no
no
yes
no
no
no
|
Sample Output
#include<stdio.h>
int main()
{
long n;
while(scanf("%d",&n)!=EOF)
{
if(n<0)
break;
if((n+2)%4==0)
printf("yes\n");
else
printf("no\n");
}
return 0;
}
水水更健康,从F(2)开始每4项就有一项能3整除,17行代码。。好简洁的说
以下是转载的代码,请尊重原创!
#include <iostream>
#include <stdio.h>
using namespace std;
int f[1000100];
int main()
{
f[0]=1; f[1]=2;
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=2;i<=n;i++)
{
f[i] = (f[i-1]+f[i-2])%3;
}
if(f[n]%3==0)
printf("yes\n");
else
printf("no\n");
}
return 0;
}