杭电1021——Fibonacci Again(找规律、简单题)
2015-11-01 14:53
555 查看
问题描述
Problem DescriptionThere 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(n),再判断是否能整除3,行不通,因为当n在150左右时,f(n)已经无法用64位整数保存了。f(n)实在太大了。所有,此法不可行。方法二:我想此类题目结果一般有规律,然后就将前100个结果打印出来。发现当(i-2)%4==0时,输出yes,其余都是no。试了一下,就A了。
AC代码
#include<stdio.h> int main() { int i; while(scanf("%d",&i)!=EOF) { if((i-2)%4==0) printf("yes\n"); else printf("no\n"); } return 0; }
相关文章推荐
- preamble码 http://zhidao.baidu.com/link?url=ObJ-VbAqYPJgIP7LF1RoulEeVhn9dHGJm9_xKKHCpalDZcI98uxH4QkN
- SHUTDOWN: waiting for active calls to complete
- Android SDK安装更新——Failed to fetch URL http://dl-ssl.google.com/android/repository/a
- 安装apk到Genymotion遇到Failure [INSTALL_FAILED_CPU_ABI_INCOMPATIBLE]
- mybatis学习(二)搭建一个xml形式的mybaits测试
- 说说 getMainLooper
- git总结(三)修改提交的author和email
- Daily Scrum (2015/10/31)
- [Django与表单]表单 CSRF verification failed 报错的解决
- nexus repair或update index 没反应 手动配置nexus index
- LightOJ - 1071 Baker Vai(记忆化搜索)
- HDOJ 2057 A + B Again
- 2015 Fall HIT Weekly Training 3
- 日本公司用人工智能帮人做金融交易
- LeetCode-Climbing Stairs
- Daily Scrum 10.31
- 进程通信aidl入门
- Heap:Moo University - Financial Aid(POJ 2010)
- lightoj 1071 - Baker Vai 【最大费用最大流】
- wait()、notify()、notifyAll()详解