Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 202 Accepted Submission(s): 71
The game is quite simple. There are n balls numbered from 1 to n and k boxes B1, B2,…, Bk satisfying following conditions:
1. With any ball x in box Bi, there must be ball 2x in box Bi+1 if there is a box Bi+1;
2. With any ball x in box Bi, there must be ball y in box Bi-1 satisfying 2y=x if there is a box Bi-1;
3. You can’t put a ball in two different boxes at the same time;
4. Your score is the number of balls in box B1;
5. The player who get the highest score win the game of course.
So, you should tell Crazygirl the highest score she can get.
Each test case has one line containing two integers n and k, meaning that there are n balls and k boxes. ( 1≤n≤1010000, 2≤k≤25 )
1 import java.io.*; 2 import java.math.*; 3 import java.util.*; 4 5 public class Main 6 { 7 public static void main(String[] args) 8 { 9 Scanner cin = new Scanner(new BufferedInputStream(System.in)); 10 BigInteger n; 11 int k; 12 int T; 13 T = cin.nextInt(); 14 while(T>0) 15 { 16 T--; 17 n = cin.nextBigInteger(); 18 k = cin.nextInt(); 19 int tmp = (1<<k); 20 BigInteger ans = BigInteger.ZERO; 21 n = n.multiply(BigInteger.valueOf(2)); 22 while(n.compareTo(BigInteger.ZERO) > 0) 23 { 24 n = n.divide(BigInteger.valueOf(tmp)); 25 BigInteger tt = n.add(BigInteger.ONE).divide(BigInteger.valueOf(2)); 26 ans = ans.add(tt); 27 } 28 System.out.println(ans); 29 } 30 } 31 }