HDU 1021.Fibonacci Again【规律】【不可直接求】【8月18】【记录】

来源:互联网 发布:阿里云ces加内存 编辑:程序博客网 时间:2024/06/06 18:00

Fibonacci Again

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
012345
 

Sample Output
nonoyesnonono
F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).给定一个n,f[n]%3==0 就输出yes,否则输出no。不能直接做的,不然超出数的范围。我打出0~40的数跟可不可以被3整除如下图所示:


你会发现,可以的n-2可以被4整除。代码如下:

#include<cstdio>int main(){    int n;    while(scanf("%d",&n)!=EOF){        if((n-2)%4==0) printf("yes\n");        else printf("no\n");    }    return 0;}



另外记录一下最近在HDU   A题的情况:


0 0
原创粉丝点击