HDU_1021_费布拉切变形
2016-05-02 15:51
197 查看
Fibonacci Again
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 50863 Accepted Submission(s): 24079
[align=left]Problem Description[/align]
There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).
[align=left]Input[/align]
Input consists of a sequence of lines, each containing an integer n. (n < 1,000,000).
[align=left]Output[/align]
Print the word "yes" if 3 divide evenly into F(n).
Print the word "no" if not.
[align=left]Sample Input[/align]
0
1
2
3
4
5
[align=left]Sample Output[/align]
no
no
yes
no
no
no
一来想把数列所有值计算出来,发现数值增长实在太快,到几百的规模时longlong就溢出了。
然后自己推了一下发现,(a+b)%c==(a%c+b%c)%c,这应该是取模运算的性质。 然后就过了。
#include<iostream> #include<cstdio> using namespace std; #define LL long long int f[1000005]; int main() { f[0]=1; f[1]=2; int t=2; while(t<1000005) { f[t]=(f[t-1]+f[t-2])%3; t++; } int n; while(scanf("%d",&n)!=EOF) { if(f ==0) printf("yes\n"); else printf("no\n"); } return 0; }
相关文章推荐
- 高吞吐量的分布式发布订阅消息系统Kafka--安装及测试
- 日常
- 如何解决Sublime Text 3不能正确显示中文的问题
- LR加载和调用dll文件
- 判断一个10^18次约数的个数(利用miller_rabin)
- 《python简明教程》学习笔记(1)-tuple和lis 4000 t
- FloatingActionButton源码解析
- ubuntu mysql5.6 数据库占用CPU过高导致机器卡死
- css两列布局,一列固定宽度,另一列自适应宽度
- Java 设置JAVA_HOME无效
- n对字母分成两组,共有多少种分法?
- servlet向jsp传递值,mysql服务器报错
- sdram汇编代码分析
- 1. crontab 简介
- java文件读写——RandomAccessFile
- DDL和DML的定义和区别
- 学习手册
- DP————1010
- CSS3新特性: mix-blend-mode: multiply
- 5-10 公路村村通 (30分) prim Kruskal 算法