A row of n meshed cogwheels drives a conveyor. Cog i has t_i teeth. Every cog starts with a painted tooth at the top. After each tooth-step, every cog advances by exactly one tooth. All the painted teeth return to the top simultaneously for the first time after a number of steps equal to the least common multiple of the tooth counts. Print that number of steps.
Line 1: an integer n, the number of cogs.
Line 2: n space-separated integers, the tooth counts t_1 ... t_n.
A single integer: the least common multiple of the n tooth counts.
Example 1
Input
3 4 6 8
Expected
24
Explanation
LCM(4,6,8) = 24, so all painted teeth align again after 24 steps.
Example 2
Input
2 7 5
Expected
35
Explanation
7 and 5 are coprime, so LCM(7,5) = 35.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →