大斐波数
来源:互联网 发布:中天证券软件下载 编辑:程序博客网 时间:2024/05/16 17:49
#include <stdio.h>#include <string.h>#define max 1005int a[max][max];int main(){ int t,n,i,j; memset(a,0,sizeof(a)); a[1][1]=1;//二维数组,高维表示项数,低维表示长度 a[2][1]=1; int sum; int carry=0; for(i=1; i<max-2; i++) { for(j=1; j<max; j++) { sum=a[i][j]+a[i+1][j]+carry; a[i+2][j]=sum%10; carry=sum/10; } } scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=max; i>0; i--) { if(a[n][i]) { break; } } for(; i>0; i--) { printf("%d",a[n][i]); } printf("\n"); } return 0;}
这个代码的用到了大数相加,开了一二维数组,把大数到序放入相应项数的数组中,例如19,a[8][1]=9 a[8][2]=1,在进行计算的时候,也是从i=1开始计算,若进位则加一,在输出的时候,因为有的数字的长度并不能把该项数行全部占满,即有的为0,如a[1][2......n]都为0,所以在查找的时候,我们就去从后往前找它第a[n][j]不为0的时候,然后输出即可
代码参考:http://blog.csdn.net/hurmishine/article/details/51388083
传送门:http://acm.split.hdu.edu.cn/showproblem.php?pid=1715
0 0
- 大斐波数
- 大斐波数
- HDU_1715 大斐波数
- HDU1715 大斐波数
- 关于大斐波数
- 1715 大斐波数
- hdoj--1715 大斐波数
- 杭电ACM 1715 大斐波数
- hdu 1715 大斐波数(大数高精)
- HDOJ 1715 大斐波数(大数+打表)
- 1293: 大斐波数(acm.zzuli.edu.cn)
- poj 1664 放苹果 dp+划分数
- js做的简单返回页
- iOS App上架流程
- 强大的sscanf正则表达式
- iOS带透明度图片的虚化
- 大斐波数
- Vsftpd本地nologin用户不能登录FTP解决办法
- argc与argv[]
- apache lighttpd nginx 对比分析
- javaScript相等运算符==
- HDU 5135 Little Zu Chongzhi's Triangles(数学题)
- Spreading the Wealth(UVa 11300)
- set/multiset用法详解
- Picasso之图片缓存机制