The Fibonacci number sequence is 1, 1, 2, 3, 5, 8, 13 and so on. You can see that except the first two numbers the others are summation of their previous two numbers. A Fibonacci Prime is a Fibonacci number which is relatively prime to all the smaller Fibonacci numbers. First such Fibonacci Prime is 2, the second one is 3, the third one is 5, the fourth one is 13 and so on. Given the serial of a Fibonacci Prime you will have to print the first nine digits of it. If the number has less than nine digits then print all the digits. Input The input file contains several lines of input. Each line contains an integer N (0 < N ≤ 22000) which indicates the serial of a Fibonacci Prime. Input is terminated by End of File. Output For each line of input produce one line of output which contains at most nine digits according to the problem statement. Sample Input 1 2 3 Sample Output 2 3 5
#include <cstdio>
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#define ll int
using namespace std;
#define mod 1000000000
const ll maxn=252005;
bool v[maxn];
ll prime[maxn],m=0;
double fb[252000];
void primes(ll n)
{
for(ll i=2; i<=n; i++)
{
if(!v[i])
{
prime[++m]=i;
for(int j=i; j<=n/i; j++)
v[i*j]=1;
}
}
}
void solve()
{
fb[1]=fb[2]=1;int bo=0;
for(int i=3; i<=252000; i++)
{
/*fb[i]=fb[i-1]+fb[i-2];
while(fb[i]>1e9)
fb[i]=fb[i]*1.0/10;*/ /*看了题解,我也不知道为什么要这样写,感觉和我注释的没大差别啊,但那个WR了,这个就能过*/
if (bo) {
fb[i] = fb[i - 1] + fb[i - 2] / 10;
bo = 0;
}
else {
fb[i] = fb[i - 1] + fb[i - 2];
}
if (fb[i] > 1e9) {
fb[i] /= 10;
bo = 1;
}
}
}
int main()
{
primes(252000);
solve();
ll n;
while(scanf("%d",&n)!=EOF)
{
if(n==1)
{
printf("2\n");
continue;
}
if(n==2)
{
printf("3\n");
continue;
}
printf("%d\n",(int)fb[prime[n]]);
}
return 0;
}