2018ACM-ICPC 焦作站现场赛 E.Resistors in Parallel(数论+高精度)

import java.math.*;
import java.util.*;
import java.io.*;

public class Main {
    public static int[] zz = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251};
    public static BigInteger[] sum = new  BigInteger[100];
    public static BigInteger[] arr = new  BigInteger[100];
    public static void init() {
        for(int i = 0; i < 54; ++i) {
            arr[i] = BigInteger.valueOf(zz[i]);
            sum[i] = BigInteger.valueOf(zz[i]);
        }
        for(int i = 1; i < 54; ++i) {
            sum[i] = sum[i-1].multiply(sum[i]);
        }
    }
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        BigInteger a, b;
        init();
        int T = cin.nextInt();
        while(T-->0) {
            BigInteger n, qqu;
            qqu = BigInteger.valueOf(1);
            n = cin.nextBigInteger();
            if(n.compareTo(qqu) == 0) {
                System.out.println("1/1");
            }
            else {
                int pos=-1;
                for(int i = 0; i < 54; ++i) {
                    if(n.compareTo(sum[i]) < 0) {
                        pos = i;
                        break;
                    }
                }
                BigInteger up, down;
                down = sum[pos-1];
                up  = BigInteger.valueOf(0);
                BigInteger x, y;
                y = BigInteger.valueOf(1);
                x = BigInteger.valueOf(1);
                for(int i = 0; i < pos; ++i) {
                    x = x.multiply(arr[i].add(y));
                }
                up = up.add(x);
                BigInteger wy;
                wy = up.gcd(down);
                System.out.print(down.divide(wy));
                System.out.print('/');
                System.out.println(up.divide(wy));
            }
        }
    }
}

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值