How to maximize $a%b$ by multiplying it with any non-negative integer?

57 Views Asked by At

What is the maximum value we can attain for the following function? Maximum is obtained at which n?

$f(a,b)=(n*a) mod (b) $
n is any natural number and we can vary it to maximize the function. a and b are fixed

What is intuition behind solving such problems?