Problem - B - Codeforces

int n,k;
int i=k-1;

can anyone tell me why there is
in last line
after n/i*k

The loop is checking for when x mod k divides n
So, i = x mod k
(x div k) (x mod k) = n
floor(x div k) = n / i (Replacing x mod k = i)
Since floor division is equivalent of removing the remainder and dividing,
floor(x div k) = (x - i) / k
Replacing in the original equation again,
x - i / k = n / i
x - i = n/i * k
x = n/i * k + i

Hope that made sense.

1 Like

ohhh… got it thanks a lot brother