斐波那契之 大数模拟(+)
发布时间:2020-12-14 03:34:38 所属栏目:大数据 来源:网络整理
导读:PS:n=1000 #include iostream#include stdio.h#include stdlib.h#include string.h#include algorithmconst int r = 1100;const int c = 500;using namespace std;int a[r][c];int n,T,st,wz;void init(){ memset(a,sizeof(a)); st = 0; wz = 0;}void moni(i
PS:n<=1000 #include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <algorithm> const int r = 1100; const int c = 500; using namespace std; int a[r][c]; int n,T,st,wz; void init() { memset(a,sizeof(a)); st = 0; wz = 0; } void moni(int mm) { for(int i=mm;i<r;i++) { for(int j=0;j<c;j++) { st =(a[i-1][j]+a[i-2][j]+a[i][j]); a[i][j]=st%10; a[i][j+1]=st/10; } } } int main() { init(); a[0][0]=1; a[1][0]=1; moni(2); cin>>T; while(T--) { cin>>n; for(int i=c-1;i>=0;i--) { if(a[n][i]!=0) { wz=i; break; } } for(int i=wz;i>=0;i--) printf("%d",a[n][i]); cout<<endl; } return 0; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |