hdu1250
2015-08-23 10:41
204 查看
Hat's Fibonacci
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9310 Accepted Submission(s): 3039
Problem Description
A Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1.
F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n>4) = F(n - 1) + F(n-2) + F(n-3) + F(n-4)
Your task is to take a number as input, and print that Fibonacci number.
Input
Each line will contain an integers. Process to end of file.
Output
For each case, output the result in a line.
Sample Input
100
Sample Output
4203968145672990846840663646
Note:
No generated Fibonacci number in excess of 2005 digits will be in the test data, ie. F(20) = 66526 has 5 digits.
#include<iostream> #include<cstring> using namespace std; int main() { int a[5][2010]; int i,j; int temp; int n,len; while(cin>>n) { memset(a,0,sizeof(a)); a[0][0]=a[1][0]=a[2][0]=a[3][0]=1; len=1; for(i=4;i<n;i++) { temp=0; for(j=0;j<len;j++) { temp+=a[(i-4)%5][j]+a[(i-3)%5][j]+a[(i-2)%5][j]+a[(i-1)%5][j]; a[i%5][j]=temp%10; temp/=10; } while(temp) { a[i%5][j++]=temp%10; temp/=10; } len=j; } len--; for(;len>=0;len--) cout<<a[(n-1)%5][len]; cout<<endl; } return 0; }
相关文章推荐
- 新的开始
- Cisco路由器启动过程
- cocos2d 移植android遇到的问题
- Cisco路由器交换机密码恢复
- 黑马程序员----Java集合框架学习笔记1-List 与Set
- 初入职场感悟
- 虚拟机Linux与windows建立网络连接
- 深入分析 Docker 镜像原理
- 改变图像的对比度和亮度
- MFC绘图总结(2):客户区大小和DC | 求索阁+http://qiusuoge.com/10069.html(转载)
- cmake学习
- 机器学习之模型选择(交叉验证)
- Cisco交换机初始化管理
- nyoj(南阳理工学院) 探 寻 宝 藏
- count有关
- 心脏与阴影,求阴影部分
- 前部分的总结和思考
- C语言选择菜单的试手程序!
- css引入方法
- 窗口与视口