npmjs 中文:C语言题目!!急!!!!

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/28 11:19:23
There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2)
Input
Input consists of a sequence of lines, each containing an integer n. (n < 1,000,000)
Output
Print the word "yes" if 3 divide evenly into F(n).(被三整除)
Print the word "no" if not.
Sample Input
0
1
2
3
4
5
sample Output
no
no
yes
no
no
no

比较偷懒的方法,先确定要输入的行数,然后再依次输入各行数值 ....
#include "stdio.h"

int get_Fibanocci(int data){
if(data==0)return 7;
if(data==1)return 11;
return get_Fibanocci(data-1)+get_Fibanocci(data-2);
}
void main(){
int num;
printf("First input the number of the lines:\n");
scanf("%d",&num);
printf("Input a sequence of a lines:\n");
int *data=new int[num];
for(int i=0;i<num;i++)
scanf("%d",&data[i]);

printf("the result:\n");
for(int j=0;j<num;j++){
data[j]=get_Fibanocci(data[j]);
if(data[j]%3==0)printf("yes\n");
else printf("no\n");
}
}
测试一下,四十以上算起来就有困难了,把问题考虑简单了嘿嘿....

问题描述:
There are another kind of Fibonacci numbers: F(0) = 7, F(1)

= 11, F(n) = F(n-1) + F(n-2) (n>=2)
Input
Input consists of a sequence of lines, each containing an

integer n. (n < 1,000,000)
Output
Print the word "yes" if 3 divide evenly into F(n).(被三整除


Print the word "no" if not.
Sample Input
0
1
2
3
4
5
sample Output
no
no
yes
no
no
no

算法分析:
这是一道数学题,从数据的凶险性(n<=1000000)可以看出。
所以我们对其余数进行分析:
f(0)≡1(mod 3,下同);
f(1)≡2;
f(2)≡0;
f(3)≡2;
f(4)≡2;
f(5)≡1;
f(6)≡0;
……
出现循环,据此我们可以发现规律:
f(n)(n+2≡0(mod 4))≡0(mod 3);
即数列中第2,6,10,14,18,……能被3整除。

输入输出:
由于输入没有特定结束符号,所以我们使用文件末尾常数EOF。

数据结构:
long n;(题目要求)

程序清单:
#include<stdio.h>

int main()
{
long n;

while (scanf("%ld",&n)!=EOF)
{
if (!((n+2)%4))
printf("yes\n");
else
printf("no\n");
}
return 0;
}