CCPC女生专场重现 B: 缺失的数据范围 (二分)

123

地址: http://acm.hdu.edu.cn/showproblem.php?pid=6288

嗯嗯,  数据出的很好, 精度控制的非常不错  卡 log  函数向上取整精度, 所以  需要 自己写 log2 函数 , 2 的多少次方 接近 n


JAVA

import java.math.BigInteger;
import java.util.Scanner;
import java.lang.Math;
public class Main {
    public static BigInteger a, b, k;
    public static BigInteger one = BigInteger.ONE;
    public static BigInteger zero = BigInteger.ZERO;
    public static BigInteger two = BigInteger.valueOf(2);

    public static void main(String[] args) {

        int t;
        Scanner cin = new Scanner(System.in);
        t = cin.nextInt();
        while (t-- != 0) {
            a = cin.nextBigInteger();
            b = cin.nextBigInteger();
            k = cin.nextBigInteger();
            BigInteger l = one;
            BigInteger r =  new BigInteger("1000000000000000000000");
            BigInteger ans = one;
            while (l.compareTo(r) <= 0) {
                BigInteger mid = l.add(r).divide(two);

                BigInteger q = mid.pow(a.intValue());  // n^a

                int cot = 1;   // log2n
                BigInteger log = two;
                while (log.compareTo(mid) < 0) {
                    cot++;
                    log = log.multiply(two);
                }
                BigInteger p = q.multiply( BigInteger.valueOf(cot).pow(b.intValue()) );   // log2n ^b

                if( p.compareTo(k)<=0)
                {
                    l = mid.add(one);
                    ans = mid;
                }
                else
                {
                    r = mid.subtract(one);
                }
            }
            //System.out.println(l.subtract(one));
            System.out.println(ans);
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值