博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU1021
阅读量:4317 次
发布时间:2019-06-06

本文共 1075 字,大约阅读时间需要 3 分钟。

Fibonacci Again

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 65456    Accepted Submission(s): 30363

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
 
= =。。。一开始用递归,内存超限。。。随后用这个递归得出规律,就是从第二个开始每隔4个就一次YES。。。AC
 
1 #include 
2 using namespace std; 3 long FIB(long n); 4 int main() 5 { 6 long n; 7 while(cin>>n) 8 { 9 if(FIB(n)%3==0)10 cout<<"yes"<

找到规律后:

1 #include 
2 using namespace std; 3 long FIB(long n); 4 int main() 5 { 6 long n; 7 while(cin>>n) 8 { 9 if(n%4==2)10 cout<<"yes\n";11 else12 cout<<"no\n";13 }14 15 return 0;16 }

 

转载于:https://www.cnblogs.com/BOW1203/p/8000641.html

你可能感兴趣的文章
转自 zera php中extends和implements的区别
查看>>
Array.of使用实例
查看>>
【Luogu】P2498拯救小云公主(spfa)
查看>>
如何获取网站icon
查看>>
几种排序写法
查看>>
java 多线程的应用场景
查看>>
dell support
查看>>
转:Maven项目编译后classes文件中没有dao的xml文件以及没有resources中的配置文件的问题解决...
查看>>
MTK android 设置里 "关于手机" 信息参数修改
查看>>
单变量微积分笔记6——线性近似和二阶近似
查看>>
补几天前的读书笔记
查看>>
HDU 1829/POJ 2492 A Bug's Life
查看>>
CKplayer:视频推荐和分享插件设置
查看>>
CentOS系统将UTC时间修改为CST时间
查看>>
redis常见面试题
查看>>
导航控制器的出栈
查看>>
玩转CSS3,嗨翻WEB前端,CSS3伪类元素详解/深入浅出[原创][5+3时代]
查看>>
iOS 9音频应用播放音频之播放控制暂停停止前进后退的设置
查看>>
Delphi消息小记
查看>>
HNOI2016
查看>>