HDU1021-Fibonacci Again,,找规律就好了~~~
2024-09-07 09:08:27
Fibonacci Again
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 50096 Accepted Submission(s): 23727
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.
Print the word "no" if not.
Sample Input
0
1
2
3
4
5
Sample Output
no
no
yes
no
no
no
题目意思不难懂吧,,a[n]%3==0?“yes\n”:"no\n";,,可是数据高达1000000,,常规斐波那契数列到40的样子就超了,,不妨打表到40看看输出结果:
for(i=0;i<45;i++)
if(a[i]%3==0) printf("%d %d yes\n",i,a[i]);
else printf("%d %d no\n",i,a[i]);
看看输出结果认真观察发现了没,, 在i=2, 6, 10,14,18,22,26,30,34,38的时候输出yes,,,
没错,,if(n%4==2) printf("yes\n);
这样连数组都不用开了,,代码就不用贴出来了吧,,核心规律等都已呈上;
最新文章
- ThreadLocal<;T>;的是否有设计问题
- python第一天 - dict
- OPENGLES 基础(一些链接和随笔)
- python中*args和**args的不同
- dt.jar设计时rt.jar运行时
- Entityframework批量删除
- 例题6-10 The Falling Leaves,UVA699
- Integer类型值相等或不等分析
- The Woman in Red Is Seen as a Threat by Other Wom
- [HeadFirst-JSPServlet学习笔记][第三章:实战MVC]
- Sightseeing Cows(最优比率环)
- HDU 3264 Open-air shopping malls ——(二分+圆交)
- Python并发编程之多线程使用
- windows环境搭建nginx
- 【深入分析Java Web技术内幕】1、深入Web请求过程知识点
- MySQL字符集不一致的解决办法总结
- Windows 登录用户的类型
- python模块安装报错大全
- python中从内部循环直接跳出多层循环
- 〖Linux〗Linux高级编程 - 进程间通信(Interprocess Communication)