The task defines, given a
and b
, find the largest c
such that
The first constraint places the lower bound on k
, and maximizing c
equivalent to minimizing k
, taking into account the second constraint.
The lower bound for k
is given by
a = c*k <= b*k
and therefore k >= a/b
. Therefore, we just look for the smallest k
, which is a divisor of a
, for example.
if (b > a) return a; for (int k=a/b; k<=a; ++k) if (a % k == 0) { return a/k; } }
source share