1103
来源:互联网 发布:手机必备实用软件 编辑:程序博客网 时间:2024/06/17 04:37
题目描述
A Fibonacci sequence is calculated by adding the previous two members of the sequence, with
the first two members being both 1.
f (1) = 1, f (2) = 1, f (n > 2) = f (n − 1) + f (n − 2)
Your task is to take a number as input, and print that fibonacci number.
输入
100
输出
354224848179261915075
样例输入
100
样例输出
354224848179261915075
提示
No generated fibonacci number in excess of 1000 digits will be in the test data, i.e. f (20) = 6765
has 4 digits.
来源
19 June, 2011 - Waterloo local contest
#include<stdio.h>typedef struct fanum{char fnum[1001];int len;}Fanum;void strAdd(Fanum *sf1,Fanum *sf2){int i,len,flag=0;Fanum sf3;len=sf1->len>sf2->len?sf1->len:sf2->len;sf3.len=len;for(i=0;i<len;i++){sf3.fnum[i]= sf1->fnum[i]-'0'+sf2->fnum[i]-'0'+flag;flag=sf3.fnum[i]/10;sf3.fnum[i]= sf3.fnum[i]%10+'0';//转换两次}if(flag==1){sf3.fnum[i]='1';sf3.len++;}for(i=0;i<sf3.len;i++){sf1->fnum[i]=sf2->fnum[i];sf1->len=sf2->len;sf2->fnum[i]=sf3.fnum[i];sf2->len=sf3.len;}return;}int main(){Fanum f1,f2;long num,i;scanf("%d",&num);f1.len= 1;f2.len= 1;for(i=0;i<1001;i++){f1.fnum[i]='0';f2.fnum[i]='0';}f1.fnum[0]='1';f2.fnum[0]='1';while(num!=2){strAdd(&f1,&f2);num-- ;}for(i=f2.len-1;i>=0;i--)printf("%d",f2.fnum[i]-'0');printf("\n");return 1;}
1 0
- 1103
- 1103
- 1103
- 1103
- problem 1103
- hdu-1103
- uva 1103
- 1103Quicksum
- zoj 1103
- 1103pickview
- 1103内存
- UVA 1103
- 1103 -- 偶数
- UVA 1103
- BZOJ 1103
- UVA 1103
- PAT 1103
- PAT 1103
- Android 跑马灯 文字滚动
- 1053
- 深入理解Java:SimpleDateFormat安全的时间格式化
- 温故而知新之Java多线程编程(一)
- redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
- 1103
- [平面图 贪心 || 最大流] BZOJ 2939 [Poi2000]滑雪 Skiers
- Netty系列之Netty高性能之道
- AC自动机
- python学习笔记(21)--类的详解3-属性函数(@property)
- 1107
- javaWeb_Tomcat 安装与配置——day_01
- 118. Pascal's Triangle
- 第十六周—C语言 (猴子分桃)