My issue
only 30% passed with error RE(NZEC).
My 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
Scanner s = new Scanner(System.in);
TreeSet<Long> sList = new TreeSet<Long>();
for(int x = 0; x <= 50; x++){
for(int y = 0; y <= 50; y++){
if(x!= y){
long l = (long) Math.pow(2,x) +(long) Math.pow(2,y);
sList.add(l);
}
}
}
int T = s.nextInt();
for(int testCase = 0; testCase < T; testCase++){
long n=s.nextLong();
if(sList.contains(n)){
System.out.println(0);
}else{
long prev = sList.lower(n);
//prev = sList.lower(prev);
long next = sList.higher(n);
System.out.println(Math.min(Math.abs(n-prev),Math.abs(next-n)));
}
}
}
}
Problem Link: SHKNUM Problem - CodeChef