hdu 4577 X-Boxes 大数

java水过……

代码如下:

 

 1 import java.math.*;
 2 import java.util.*;
 3 public class Main {
 4     public static void main(String arg[]){
 5         BigInteger n,ans,sum;
 6         Scanner cin = new Scanner(System.in);
 7         int k,t=cin.nextInt();    
 8         while(t-->0){
 9             n=cin.nextBigInteger();
10             k=cin.nextInt();
11             ans=BigInteger.ZERO;
12             while(true){
13                 n=n.divide(BigInteger.valueOf(1<<(k-1)));
14                 sum=n.subtract(n.divide(BigInteger.valueOf(2)));
15                 if(sum.equals(BigInteger.ZERO)) break;
16                 ans=ans.add(sum);
17                 n=n.divide(BigInteger.valueOf(2));
18             }
19             System.out.println(ans);
20         }
21     }
22 }
View Code

 

 

 

posted @ 2013-08-10 18:47  _随心所欲_  阅读(370)  评论(0编辑  收藏  举报