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

HDU 1021

时间:2019-02-07 17:42:36      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:inpu   mem   nbsp   can   nsis   sequence   each   text   ble   

Fibonacci Again

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


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
 
解法:
 1 #include<stdio.h>
 2 int main(){
 3     int i,n,f[10000];
 4     f[0] = 7;
 5     f[1] = 11;
 6     while(scanf("%d",&n)!=EOF){
 7         for(i=2; i<=n; i++){
 8             f[i] = f[i-1]+f[i-2];
 9         }
10         if(f[n]%3 == 0)
11             printf("yes\n");
12         else printf("no\n");
13     }
14     return 0;
15 }

 

后来,get一个规律:n除4余2的就输出yes,否则no。
 1 #include<stdio.h>
 2 int main(){
 3     int n;
 4     while(scanf("%d",&n)!=EOF){
 5         if(n%4==2)
 6             printf("yes\n");
 7         else printf("no\n");
 8     }
 9     return 0;
10 }

 

 
 
 
 
 
 
 
 
 
 
 
 

HDU 1021

标签:inpu   mem   nbsp   can   nsis   sequence   each   text   ble   

原文地址:https://www.cnblogs.com/fangxiaoqi/p/10354975.html

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