import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer("");
int cases=Integer.parseInt(br.readLine());
for(int i=0;i<cases;i++) {
String[]str=br.readLine().split(" ");
long n=Integer.parseInt(str[0]);
long x=Long.parseLong(str[1]);
String tempX=Long.toBinaryString(x);
if(x==0)
sb.append(numOfOnes(tempX)).append(" 1").append("\n");
else
sb.append(numOfOnes(tempX)).append(" ").append((long)Math.pow(2, n)-numOfTZero(tempX)).append("\n");
}
System.out.print(sb);
}
static int numOfOnes(String x){
int counter=0;
for(int i=0;i<x.length();i++){
if(x.charAt(i)=='1'){
counter++;
}
}
return counter+1;
}
static int numOfTZero(String x){
int ans=0;
for(int i=x.length()-1,tw=1;i>-1;i--){
if(x.charAt(i)=='1'){
break;
}
ans+=tw;
tw*=2;
}
return ans;
}
}
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer("");
int cases=Integer.parseInt(br.readLine());
for(int i=0;i<cases;i++) {
String[]str=br.readLine().split(" ");
long n=Integer.parseInt(str[0]);
long x=Long.parseLong(str[1]);
String tempX=Long.toBinaryString(x);
if(x==0)
sb.append(numOfOnes(tempX)).append(" 1").append("\n");
else
sb.append(numOfOnes(tempX)).append(" ").append((long)Math.pow(2, n)-numOfTZero(tempX)).append("\n");
}
System.out.print(sb);
}
static int numOfOnes(String x){
int counter=0;
for(int i=0;i<x.length();i++){
if(x.charAt(i)=='1'){
counter++;
}
}
return counter+1;
}
static int numOfTZero(String x){
int ans=0;
for(int i=x.length()-1,tw=1;i>-1;i--){
if(x.charAt(i)=='1'){
break;
}
ans+=tw;
tw*=2;
}
return ans;
}
}
No comments:
Post a Comment