Loop to find the maximum value of count_P that also satisfy P * count_P + Q * count_Q = N
while ( N > 0 ) { if ( N % P == 0 ) { count_P += Math . floor ( N / P ) ; N = 0 ; } else { N = N - Q ; count_Q ++ ; } }