其实,答案就是2(n - 1)。
写个大数而已。熟悉一下java的大数吧算是,很有用,却会忘……
import java.math.BigInteger;
import java.util.*;
public class Hdoj1819 {
public static void main(String args[]) {
BigInteger two = new BigInteger("2");
BigInteger res;
Scanner cin = new Scanner(System.in);
while(cin.hasNext()) {
BigInteger n;
n = cin.nextBigInteger();
if(n.equals(BigInteger.ONE)) {
System.out.println("1");
continue;
}
n = n.subtract(BigInteger.ONE);
res = n.multiply(two);
System.out.println(res);
}
}
}
本文介绍了一个使用Java进行大数运算的例子,具体为计算2(n-1),通过实例展示了BigInteger类的应用,适用于处理超出基本数据类型范围的数值计算。

20万+

被折叠的 条评论
为什么被折叠?



