Fibonacci
来源:互联网 发布:茶水浇花知乎 编辑:程序博客网 时间:2024/05/22 04:50
问题 C: Fibonacci
提交状态
题目描述
In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For example, the first ten terms of the Fibonacci sequence are:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, …
An alternative formula for the Fibonacci sequence is
.
Given an integer n, your goal is to compute the last 4 digits of Fn.
输入
The input test file will contain multiple test cases. Each test case consists of a single line containing n (where 0 ≤ n ≤ 1,000,000,000). The end-of-file is denoted by a single line containing the number −1.
输出
For each test case, print the last four digits of Fn. If the last four digits of Fn are all zeros, print ‘0’; otherwise, omit any leading zeros (i.e., print Fn mod 10000).
样例输入
099999999991000000000-1
样例输出
0346266875
#include <stdio.h>int main(){int n,k1,k2,k3,i,k,sum,l,a[38324],h;while(scanf("%d",&n)!=EOF){if(n == (-1)){ break; }else if(n<=2){printf("%d\n",n);}else{k1 = 0;k2 = 1;for(i = 3;i<=n+1;i++){k1 = k1 % 10000;
k2 = k2 % 10000;
<pre name="code" class="html"> k3 = k1 + k2;k1 = k2;
<span style="font-family: Arial, Helvetica, sans-serif;">k2 = k3;</span>k3 = k3 % 10000; }printf("%d\n",k3); } }return 0;}
0 0
- Fibonacci
- fibonacci
- Fibonacci
- Fibonacci
- Fibonacci
- fibonacci
- Fibonacci
- Fibonacci
- Fibonacci
- Fibonacci
- Fibonacci
- Fibonacci
- Fibonacci
- Fibonacci
- Fibonacci
- Fibonacci
- Fibonacci
- Fibonacci
- protel dxp 2004电路仿真
- 前序,中序,后序排列互相转化
- 第14天新手SEO基础计划之:网络社区
- VC2010配置OpenGL常见问题
- LinkedList
- Fibonacci
- FileReader的一个问题
- 第15天新手SEO基础计划之:创新营销
- 如何修改表单向导中的信息列表页面
- 获取豆瓣FM的数据(频道列表,歌曲列表)
- matlab绘图、计算基本函数(二)
- mybatis如何读取clob数据 详细过程
- 自定义组件—MyButton
- Android ActionBar完全解析,使用官方推荐的最佳导航栏(上)