As usual, Tom and Jerry are fighting. Tom has strength
and Jerry has strength . You are given and your task is to find the number of possible values of such that Jerry wins the following game.
The game consists of one or more turns. In each turn:
- If both and are even, their values get divided by and the game proceeds with the next turn.
- If both and are odd, a tie is declared and the game ends.
- If is even and is odd, Tom wins the game.
- If is odd and is even, Jerry wins the game.
Find the number of possible initial values of such that , there is no tie and Jerry wins the game.
Input
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first and only line of each test case contains a single integer .
Output
For each test case, print a single line containing one integer ― the number of values of such that Jerry wins the game.
Constraints
Subtasks
Subtask #1 (20 points):
Subtask #2 (80 points): original constraints
Example Input
2
1
11
Example Output
0
5
Explanation
Example case 1: We must have , but in this case, the game ends and a tie is declared in the first turn.
Example case 2: If , then is even and is odd, so Jerry wins the game in the first turn. Any odd value of leads to a tie instead.
Code
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
try {
Scanner sc =new Scanner(System.in);
int t = sc.nextInt();
for(int i=0;i<t;i++){
long ts = sc.nextLong();
while(ts%2==0){
ts=ts/2;
}
System.out.println(ts/2l);
}
}
catch (Exception e) {
// TODO: handle exception
}
}
}
0 Comments