首页 > 其他 > 详细

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

时间:2015-08-18 21:22:52      阅读:263      评论:0      收藏:0      [点我收藏+]

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
0 1 2 3 4 5
 

Sample Output
no no yes no no no
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题的情况:

技术分享

版权声明:本文为博主原创文章,未经博主允许不得转载。

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

原文:http://blog.csdn.net/a995549572/article/details/47759235

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!