2018 焦作E java 高精度暴力

Posted 入侵检测引擎算法工程师/前ICPC选手

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2018 焦作E java 高精度暴力相关的知识,希望对你有一定的参考价值。

https://vjudge.net/problem/Gym-102028E

暴力,线性递推分母

//package acm;
import java.math.BigInteger;
import java.util.Scanner;

import com.sun.org.apache.bcel.internal.generic.SWAP;
import com.sun.org.apache.bcel.internal.generic.StackConsumer;

import sun.management.GcInfoCompositeData;
public class Main{
	public static final int maxn=1000,maxm=200000;
	public static BigInteger gcd(BigInteger a,BigInteger b) {
		if(b.compareTo(BigInteger.ZERO)==0)return a; 
		else return gcd(b, a.remainder(b));
	}
    public static void main(String[] argc){
    	int[]a=new int[maxn];
    	for(int i=2;i<maxn;i++) a[i]=i;
    	for(int i=2;i<maxn;i++) if(a[i]!=0) 
    		for(int j=i*2;j<maxn;j=j+i) a[j]=0;
    	Scanner cin=new Scanner(System.in);
    	int casn=cin.nextInt();
    	int[] prime=new int[10000]; 
    	for(int ii=1;ii<=casn;++ii) {
    		BigInteger x=cin.nextBigInteger();
    		BigInteger res=BigInteger.ONE;
    		BigInteger now=BigInteger.ONE;
    		int i=1;
    		while(true) {
    			i++;
    			if(a[i]==0) continue;
    			if(res.multiply(BigInteger.valueOf(a[i])).compareTo(x)<=0) {
    				res=res.multiply(BigInteger.valueOf(a[i]));
    				now=now.multiply(BigInteger.valueOf(a[i]+1));
    			}else break;
    		}
    		BigInteger g=gcd(res,now);
    		res=res.divide(g);
    		now=now.divide(g);
    		System.out.println(res+"/"+now);
    	}
    }
}

 

以上是关于2018 焦作E java 高精度暴力的主要内容,如果未能解决你的问题,请参考以下文章

2018焦作网络赛E

2018焦作网络赛-E- Jiu Yuan Wants to Eat

2018ACM-ICPC焦作站E题Resistors in Parallel

ACM-ICPC 2018 焦作赛区网络预赛J题 Participate in E-sports

2018焦作网络赛 E Jiu Yuan Wants to Eat(线段树+树链剖分)

ACM-ICPC 2018 焦作赛区网络预赛 E Jiu Yuan Wants to Eat (树链剖分+线段树)