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

import java.util.
class GFG {
public static void main (String[] args)throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(;
int t = Integer.parseInt(br.readLine());
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;

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;
    return result;


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

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.

Check this :

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.


Check this :

Precision issue

Got it. Thanks a lot :smiley: