/*
ID: BryatnMark
LANG: JAVA
TASK: AC
*/
import java.util.*;
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
public static void main(String args[]) throws Exception {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.main(in, out);
out.close();
}
}
class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
String next() {
if (!hasNext())
throw new RuntimeException();
return tokenizer.nextToken();
}
boolean hasNext() {
while (tokenizer == null || !tokenizer.hasMoreTokens())
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (Exception e) {
return false;
}
return true;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
BigInteger nextBigInteger() {
return new BigInteger(next());
}
}
class Task {
PrintStream cout = System.out;
final int maxn = 250000;
boolean[] vis = new boolean[maxn + 10];
int[] p = new int[maxn + 10];
int size = 0;
BigInteger M=BigInteger.TEN.pow(30);
BigInteger P=BigInteger.TEN.pow(9);
BigInteger[] f=new BigInteger [maxn+10];
int[] ans=new int [maxn+10];
void init() {
int i, j;
for (i = 2; i * i <= maxn; ++i)
if (!vis[i])
for (j = i * i; j <= maxn; vis[j] = true, j += i)
;
p[size++] = 3;
p[size++] = 4;
p[size++] = 5;
for (i = 7; i < maxn; i += 2)
if (!vis[i])
p[size++] = i;
//cout.println(size);
}
void main(InputReader in, PrintWriter out) throws Exception {
init();
int i;
f[1]=BigInteger.ONE;
f[2]=f[1];
for(i=3;i<maxn;++i)
{
f[i]=f[i-1].add(f[i-2]);
if(f[i].compareTo(M)>=0)
{
f[i]=f[i].divide(P);
f[i-1]=f[i-1].divide(P);
}
}
int k;
String s;
for(i=0;i<size;++i)
{
k=p[i];
while(f[k].compareTo(P)>=0)
f[k]=f[k].divide(BigInteger.TEN);
}
while(in.hasNext())
{
k=in.nextInt();
k=p[k-1];
out.println(f[k]);
}
}
}
UVA 10236 The Fibonacci Primes
最新推荐文章于 2020-02-19 16:37:39 发布