UVA 10236 The Fibonacci Primes

47 篇文章 0 订阅
20 篇文章 0 订阅
/*
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]);
		}
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值