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

杭电1021——Fibonacci Again(找规律、简单题)

2015-11-01 14:53 555 查看

问题描述

Problem Description

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

算法

方法一:如果先求f(n),再判断是否能整除3,行不通,因为当n在150左右时,f(n)已经无法用64位整数保存了。f(n)实在太大了。所有,此法不可行。

方法二:我想此类题目结果一般有规律,然后就将前100个结果打印出来。发现当(i-2)%4==0时,输出yes,其余都是no。试了一下,就A了。

AC代码

#include<stdio.h>

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