# 斐波那契数列

+关注继续查看

1
2
3
4
5
0

1
1
2
3
5

1、请注意，输入数据不超过1000行。
2、输入虽然是“1 2 3 4 5”，但输出显然不是“上山打老虎”。
3、小牛会使用很卑鄙的（其实是被逼的）输入数据来欺负你，所以你必须比小牛更卑鄙！

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <cstdlib>
#include <cstring>
#include <string>
#include <ctime>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;

const ll MOD = 1000000009;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-8;

const ll power = 15;
const ll base = 1e15;

const int MAXN = 2000;
struct BigNum
{
ll a[MAXN];
BigNum(){
memset(a,0,sizeof(a));
}
BigNum(char *s){
memset(a,0,sizeof(a));
int len=strlen(s);
a[0]=(len+power-1)/power;
for(ll i=0,t=0,w;i<len;w*=10,++i){
if(i%power==0){
w=1,++t;
}
a[t]+=w*(s[i]-'0');
}
}
void print(){
printf("%lld",a[a[0]]);
for (int i=a[0]-1;i>0;--i)
printf("%0*lld",power,a[i]);
printf("\n");
}
};

struct Node{
int a1,before;
BigNum ans;
};

bool cmp1(Node x,Node y){
return x.a1<y.a1;
}

bool cmp2(Node x,Node y){
return x.before<y.before;
}
BigNum operator + (const BigNum &p,const BigNum &q){
BigNum c;
c.a[0]=max(p.a[0],q.a[0]);
for(int i=1;i<=c.a[0];++i){
c.a[i]+=p.a[i]+q.a[i];
c.a[i+1]+=c.a[i]/base;
c.a[i]%=base;
}
if(c.a[c.a[0]+1])
++c.a[0];
return c;
}

Node q[1005];
int main(){
int n=0,k;
while(cin>>k){
if(k==0)
break;
q[n].a1=k;
q[n].before=n;
n++;
}
sort(q,q+n,cmp1);
char b[]="1";
BigNum s1(b),s2(b),temp;
int j=3;
for(int i=0;i<n;i++){
if(q[i].a1==1||q[i].a1==2){
q[i].ans=s1;
}
else{
for(;j<=q[i].a1;j++){
temp=s1;
s1=s2;
s2=temp+s1;
}
q[i].ans=s2;
}
}
sort(q,q+n,cmp2);
for(int i=0;i<n;i++){
q[i].ans.print();
}
return 0;
}

21678 0

25232 0

18714 0

19217 0

18989 0

20690 0

13975 0

35345 0

10006 0
+关注
buct_di

30

0

JS零基础入门教程（上册）