这是另外一种斐波那切数列.F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2) 每行输入一个数n。
答案:2 悬赏:0
解决时间 2021-01-19 10:54
- 提问者网友:几叶到寒
- 2021-01-18 20:56
这是另外一种斐波那切数列.F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2) 每行输入一个数n。
最佳答案
- 二级知识专家网友:鱼忧
- 2021-01-18 21:56
#include
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;
}
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;
}
全部回答
- 1楼网友:白昼之月
- 2021-01-18 22:45
#include<stdio.h>
int mod3( int x )
{
int a,b,c,i;
if( x == 0 )
return 7 % 3;
else if( x == 1 )
return 11 % 3;
else
{
a = 7; b = 11;
while( --x > 0 )
{
c = ( a + b ) % 3;
a = b;
b = c;
}
return c % 3;
}
}
int main( void )
{
int input;
while( scanf( "%d", &input ) != EOF )
if( mod3( input ) == 0 )
printf( "yes\n" );
else
printf( "no\n" );
return 0;
}
//============================
//或者更简单点
#include<stdio.h>
int main( void )
{
int input;
while( scanf( "%d", &input ) != EOF )
if( input % 4 == 2 )
printf( "yes\n" );
else
printf( "no\n" );
return 0;
}
int mod3( int x )
{
int a,b,c,i;
if( x == 0 )
return 7 % 3;
else if( x == 1 )
return 11 % 3;
else
{
a = 7; b = 11;
while( --x > 0 )
{
c = ( a + b ) % 3;
a = b;
b = c;
}
return c % 3;
}
}
int main( void )
{
int input;
while( scanf( "%d", &input ) != EOF )
if( mod3( input ) == 0 )
printf( "yes\n" );
else
printf( "no\n" );
return 0;
}
//============================
//或者更简单点
#include<stdio.h>
int main( void )
{
int input;
while( scanf( "%d", &input ) != EOF )
if( input % 4 == 2 )
printf( "yes\n" );
else
printf( "no\n" );
return 0;
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯