Resistors in Parallel (Gym-102028E)

Problem Description

In this physics problem, what we are concerned about are only resistors. If you are poor at physics, do not worry, since solving this problem does not require you to have advanced abilities in physics.

Resistors are said to be connected together in parallel when both of their terminals are respectively connected to each terminal of the other resistors.

We have the following parallel resistor equation for k resistors with resistances R1, R2, ..., Rk in parallel and their combined resistance R:

Now you have n resistors, the i-th of which has a resistance of ri ohms with the equation

You also have n selections, the i-th of which is a set of resistors Si such that

Please find a selection in which the resistors form a parallel resistor with the minimum resistance and output the reduced fraction  of its resistance.

Input

The input contains several test cases, and the first line contains a positive integer T indicating the number of test cases which is up to 100.

For each test case, the only one line contains an integer n, where 1 ≤ n ≤ 10100.

Output

For each test case, output a line containing a reduced fraction of the form p/q indicating the minimum possible resistance, where p and q should be positive numbers that are coprime.

Examples

Input

3
10
100
1000

Output

1/2
5/12
35/96

题意:给出一个小于等于 n 的无平方因子数,其阻值是其所有因子的倒数和的倒数,求其最小阻值

思路:打表找规律即可发现,小于 n 的连续素数积即为答案,其阻值是因子倒数和的倒数,由于 n 极大,因此需要用大数来写

Source Program

import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    static int []a=new int[1005];
    static int N=200005;
    static long []prime = new long[N];
    static long num_prime = 0; //prime存放着小于N的素数
    static int []isNotPrime =new int[N];
    public static void main(String[] args)  {
        Scanner in=new Scanner(System.in);
        prime[0]=0;
        isNotPrime[0]=1;
        isNotPrime[1]=1;
        getPrime();
        int t=in.nextInt();
        while((int) t-->0) {

            BigInteger n=in.nextBigInteger();

            BigInteger sum1=new BigInteger("1");
            BigInteger sum2=new BigInteger("1");

            int i=0;
            while(true) {
                if(sum1.multiply(new BigInteger(String.valueOf(prime[i]))).compareTo(n)<=0) {
                    sum1=sum1.multiply(new BigInteger(String.valueOf(prime[i])));
                    sum2=sum2.multiply(new BigInteger(String.valueOf(prime[i]+1)));
                } else
                    break;
                i++;
            }
            BigInteger g=Gcd(sum1,sum2);
            sum1=sum1.divide(g);
            sum2=sum2.divide(g);
            System.out.println(sum1+"/"+sum2);
        }
    }
    static BigInteger  Gcd(BigInteger a,BigInteger b) {
        if(b.compareTo(new BigInteger("0"))==0)
            return a;
        else
            return Gcd(b, a.mod(b));
    }
    static void getPrime() {
        for(long  i=2; i<N; i++) {
            if(isNotPrime[(int)(i)]==0)
                prime[(int) num_prime ++]=i;
            //无论是否为素数都会下来
            for(long  j=0; j<num_prime && i*prime[(int)j]<N; j++) {
                isNotPrime[(int) (i * prime[(int)(j)])] = 1;
                if( (i % prime[(int)(j)] )==0 )  //遇到i最小的素数因子
                    //关键处1
                    break;
            }
        }
    }
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值