标签:
0 1 2 3 4 5
no no yes no no no
#include<iostream>
using namespace std;
int diaoyong(int n)
{
if(n>=2)
return diaoyong(n-1)+diaoyong(n-2);
if(n==1)
return 11;
if(n==0)
return 7;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF) //f[4]=3 + 2=2+1 +1+0 =1+0+1+1+0=33+14=47
{
if(diaoyong(n)%3==0)
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
return 0;
}正确的解法是:实际可以找到规律的,仔细想想。让是不是能被3整除,能被3整除的,即余数是0的,输出yes,否则,输出no。所以我把对3取余的数列举一下:#include<iostream>
using namespace std;
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
if(n%8==2 ||n%8==6)
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
return 0;
}标签:
原文地址:http://blog.csdn.net/zuguodexiaoguoabc/article/details/43816665