Solution to CHEFSEG failing some test cases.

Here is my solution to problem CHEFSEG of november long challenge. My solution is giving wrong answer for subtask 3. I guess it has something to do with precision. can anyone help me? here is link to my solution

public static void main(String[] args) {
	// TODO Auto-generated method stub
	MyScanner scan = new MyScanner();
	
	int test = scan.nextint();
	for(int t=0; t<test; t++)
	{
		int x=scan.nextint();
		
		long k = scan.nextLong();
		
		int level = ((int)(Math.log(k)/Math.log(2)+1e-10))+1;
		
		
		int finished = (int) Math.pow(2, level-1)-1;
		
		
		double div = Math.pow(2, level);
		
		
		double res=x/div;
		
		
		res=(2*(k-finished)-1)*res;
		
		NumberFormat formatter = new DecimalFormat("###.###############");  
		String f = formatter.format(res);  
		System.out.println(f);
		
	}
}

Sharing code, that is not compilable is useless…

ok. http://www.codechef.com/viewsolution/5457231 here is link to my solution.

for

2
1 100000000000
1 1000000000000

it returns numbers greater than 1…

1 Like

Thanks. It is accepted. Changed variable finished to long.