杭电1021Fibonacci Again
2016-02-02 17:49
465 查看
C Fibonacci Again
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status
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
Sample Output
一开始直接把所有的f[i]算出来了,但是忽略了最后发f[i]会很大
所以使用同余定
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status
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[i]算出来了,但是忽略了最后发f[i]会很大
所以使用同余定
#include<stdio.h> int f[1000000]; int main() { int n; f[0]=1; f[1]=2; for(int i=2;i<1000000;i++) f[i]=(f[i-1]+f[i-2])%3; while(~scanf("%d",&n)) { if(f ==0) printf("yes\n"); else printf("no\n"); } return 0; }
相关文章推荐
- canvas和paint得简单应用
- BZOJ 3262 陌上花开、HDU 5618 Jam's problem again(三维偏序、cdq分治 + BIT)
- rails 分页插件 Kaminari 的 数组分页
- 【Elasticsearch】打分策略详解与explain手把手计算
- 解决'libproxychains.so.3' from LD_PRELOAD cannot be preloaded问题
- mongodb的 failindexkeytoolong
- HUD 1022-Train Problem I
- 真机测试libUMSocial_Sdk_4.2.2.a(UMSShareListController.o)' does not contain bitcode.
- flash air中读取本地文件的三种方法
- 解决Failed to load class "org.slf4j.impl.StaticLoggerBinder"
- HDU 1082 Matrix Chain Multiplication
- What is a fully qualified domain name (FQDN)?
- Failed to initialize monitor Thread: Unable to establish loopback connection解决方法
- pair模板类
- hdu5618 Jam's problem again(cdq分治)(BestCoder Round #70)
- MyBaits关联查询一对一、一对多
- 五子棋AI算法第一篇-我对谷歌Alphago的看法
- Lets write a Tiny IoC Container to learn and for fun
- HDU 5618 Jam's problem again (cdq分治+树状数组)
- [原创] zabbix学习之旅四:mail客户端安装