找规律hdu4577

来源:互联网 发布:七政四余择日软件 编辑:程序博客网 时间:2024/06/10 22:10
import java.util.*;import java.io.*;import java.math.BigInteger;public class Main {public static void main(String[] args){Scanner sc = new Scanner(System.in);int T=sc.nextInt();for(int kase=0;kase<T;kase++){BigInteger n = sc.nextBigInteger();int m=sc.nextInt();BigInteger two=BigInteger.valueOf(2);BigInteger t =two.pow(m-1);BigInteger sum = BigInteger.ZERO;while(n.compareTo(BigInteger.ZERO)>0){n = n.divide(t);sum = sum.add(n).subtract(n.divide(two));n = n.divide(two);}System.err.println(sum);}}}

0 0
原创粉丝点击