您的位置:首页 > 大数据 > 人工智能

hdu 1021 Fibonacci Again

2015-09-16 10:29 671 查看

Fibonacci Again

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 44959 Accepted Submission(s):
21451


[align=left]Problem Description[/align]
There are another kind of Fibonacci numbers: F(0) = 7,
F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).

[align=left]Input[/align]
Input consists of a sequence of lines, each containing
an integer n. (n < 1,000,000).

[align=left]Output[/align]
Print the word "yes" if 3 divide evenly into
F(n).

Print the word "no" if not.

[align=left]Sample Input[/align]

0

1

2

3

4

5

[align=left]Sample Output[/align]

no
no

yes
no
no
no

[align=left]Author[/align]
Leojay

[align=left]Recommend[/align]
JGShining | We have carefully selected several
similar problems for you: 1071 1032 1170 1028 1022

简单的找规律,打表后发现每4个一次循环。

题意:按题意 F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2) 这个公式求值,判断这个F
是否是3的倍数,是输出yes,不是输出no。

附上代码:

#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
int n;
while(~scanf("%d",&n))
{
if((n-2)%4==0)
printf("yes\n");
else
printf("no\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: