题目链接:The Chosen One
比赛链接:ICPC Asia Nanning 2017
题意
(t) 组样例,每组给出一个整数 (n(2le nle 10^{50})),求不大于 (n) 的最大的 (2) 的整数次幂。
题解
高精度运算
Java BigInteger 中的 bitLength() 方法可以直接计算某个大数二进制表示下的位数。
更多关于 Java BigInteger 的操作参见我的另一篇文章 大数运算之 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));
}
}
}
转载于:https://www.cnblogs.com/wulitaotao/p/11360526.html
最后
以上就是过时春天最近收集整理的关于ICPC Asia Nanning 2017 F. The Chosen One (高精度运算)的全部内容,更多相关ICPC内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复