码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-08-18 21:23:33      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:规律   acm   c++   hdu   1021   

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】

标签:规律   acm   c++   hdu   1021   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!