Plz help me debug this code(Chef and Ingredients). I don't know why one Test case failed

import java.io.;
import java.util.
;
class GFG {
public static void main (String[] args)throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while(t–>0)
{
String s[] = br.readLine().split(" ");
long n = Long.parseLong(s[0]);
long k = Long.parseLong(s[1]);
long mod = 1000000007;
long d = (n-1);
long x = ((k-1)%d);
long a = (x==0 ? d : x);
long N =(long) (Math.ceil((k-1)/(double)d));
long ans = (((N%mod)((2(a%mod))%mod+(((N-1)%mod)(d%mod))%mod)%mod)%modlittle(2,mod))%mod;
System.out.println(ans);

	}
}
public static long little(long n, long mod)
{
    return exponential(n,mod-2,mod);
}
public static long exponential(long n, long p, long mod)
{
    long result=1;
    while(p>0)
    {
        if(p%2==1)
            result=(result*n)%mod;
        n=(n*n)%mod;
        p/=2;
    }
    return result;
}

}

Any link to this code? Just wanted to see the cases it passed.

https://www.codechef.com/viewsolution/24720416

Improve your Modulo multiplication, it will work.
See here

Thanks for your suggestion, but can you please point out in my code where the mod is wrong.

@sha_shank_96
Check this :
https://www.codechef.com/viewsolution/24854417

I modified your code a bit.
Replaced the ceil function in line 16,thats it.

Can you please explain how your code change is working.

@sha_shank_96

Check this :

Precision issue

@bits38
Got it. Thanks a lot :smiley: