CodeChef A

时间:2021-05-10 22:10:52

问题是求出斐波那契数列的第n个,这里要用大数加法预处理,然后就可以了

代码:

CodeChef   ACodeChef   A
 #include <iostream>
#include <sstream>
#include <cstdio>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <string>
#include <stack>
#include <map>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#define esp 1e-6
#define pi acos(-1.0)
#define pb push_back
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define mp(a, b) make_pair((a), (b))
#define in freopen("in.txt", "r", stdin);
#define out freopen("out.txt", "w", stdout);
#define print(a) printf("%d\n",(a));
#define bug puts("********))))))");
#define stop system("pause");
#define Rep(i, c) for(__typeof(c.end()) i = c.begin(); i != c.end(); i++)
#define inf 0x0f0f0f0f using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VII;
typedef vector<pii, int> VIII;
typedef VI:: iterator IT;
struct BigInt
{
int len;
int f[];
void Init(int n)
{
memset(f, , sizeof(f));
len = ;
while(n)
{
f[len] = n % ;
n /= ;
len++;
} if(len > )
len--;
}
BigInt operator + (const BigInt &a)const
{
int carry = ;
BigInt c;
c.Init();
int i;
for(i = ; i <= max(a.len, len); i++)
{
carry = carry + f[i] + a.f[i];
c.f[i] = carry%;
carry /= ;
}
if(carry == )
return c.len = i - , c;
while(carry)
{
c.f[i] = carry%;
carry /= ;
i++;
}
c.len = i-;
return c;
}
}; BigInt fi[];
int main(void)
{
fi[].Init();
fi[].Init();
for(int i = ; i <= ; i++)
fi[i] = fi[i-] + fi[i-];
int t;
while(scanf("%d", &t), t)
{
for(int i = fi[t].len; i >= ; i--)
printf("%d", fi[t].f[i]);
puts("");
}
return ;
}