ICPC Asia Nanning 2017 F. The Chosen One (precision arithmetic)

Topic links: at The Chosen One

The meaning of problems

\ (T \) set of sample, given each an integer \ (n-(2 \ n-Le \ Le 10 ^ {50}) \) , find no greater than \ (n-\) maximum \ (2 \) the integer power.

answer

Precision Operational

Java BigIntegerThe bitLength()method digits in a binary representation of large numbers can be calculated directly.

More about Java BigIntegerthe operations, refer to my other article the basic usage of computing large numbers of Java BigInteger

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

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        while (t-->0){
            BigInteger n = in.nextBigInteger();
            BigInteger ans = new BigInteger("2");
            System.out.println(ans = ans.pow(n.bitLength() - 1));
        }
    }
}

Guess you like

Origin www.cnblogs.com/wulitaotao/p/11360526.html