Let cc be the number of cats and dd is the number of dogs. As we’ve to distribute mxm-x chocolates and cakes equally, cc and dd must be divisor of mxm-x and the duration is c×dc\times d. So, find all the divisors of mxm-x which are greater than xx. Then, for each divisor, find the minimum divisor by a binary search for which the multiple of them will be equal or greater than mm. Overall time complexity O(t×(mx+DlogD))O(t\times (\sqrt{m-x} + DlogD)) where DD is the number of divisors.

Statistics

69% Solution Ratio
Farhan20Earliest, Nov '21
kamolPaulFastest, 0.2s
swati_1952Lightest, 131 kB
FrdhsnShortest, 829B
Toph uses cookies. By continuing you agree to our Cookie Policy.