B - Even Number Theory
ZOJ - 4091
&:这题给了很多的定义,把定义读懂就会了,用 Java 比较好写。比赛的时候最后看到了,也想到了,可惜前面的有几道题在写,就没实现一下,有点可惜。
代码语言:javascript复制import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t;
t = sc.nextInt();
while(t -- > 0){
BigInteger n = null;
n = sc.nextBigInteger();
BigInteger x = new BigInteger("2");
BigInteger p = new BigInteger("0");
BigInteger sum = new BigInteger("0");
while(n.compareTo(p) != 0)
{
sum = sum.add(n.divide(x));
n = n.divide(x);
}
System.out.println(sum);
}
}
}