Combine periods with a safe LCM
Divide first and guard the product that remains.
Understand the idea
For positive a and b, lcm(a,b) = (a/gcd(a,b)) × b. GCD takes minimum prime exponents and LCM takes maxima. Dividing first avoids an unnecessarily large intermediate product, but the final result still must fit.
Trace a small example
Periods 12 and 18 coincide every 36 units. For cap L and positive b, set q = a/gcd(a,b); if q > L/b, the LCM exceeds L without calculating an unsafe product. On a circle, n/gcd(n,k) moves of size k return to the start.
Conditions and cost
Handle zero inputs before division: the usual nonnegative LCM convention returns zero if either input is zero. Circle formulas require n > 0. Signed input normalization and final-product bounds are separate obligations.
Does dividing by the GCD guarantee the LCM fits?
Turn the idea into code
On a circle of 12 positions, how many moves of size 8 return to the start?
Give me a hint
Find n/gcd(n,k).
Show the explained solution
12/4 = 3 moves: 0 → 8 → 4 → 0.
Your notes
Mark complete when you can explain it yourself.