int n,k;

cin>>n>>k;

int i=k-1;

while(n%i!=0)

{

i–;

}

cout<<n/i*k+i<<endl;

can anyone tell me why there is

+i

in last line

after n/i*k

int n,k;

cin>>n>>k;

int i=k-1;

while(n%i!=0)

{

i–;

}

cout<<n/i*k+i<<endl;

can anyone tell me why there is

+i

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