Planetary Alignment
InterviewTime limit2sMemory limit1024 MB
Given the alignment periods T_1 to T_(N-2) for each triple of consecutive planets, find the period at which all N planets line up.
- Level
Easy3 of 10
- Topics
- Math, Number theory
- Solved
- No attempts yet
Problem
Planetary alignment is when planets appear to lie in a straight line. After 18 years, a planetary alignment could be observed from Earth again.
Junseo lives on Earth in a parallel world, where planets can be observed. Junseo wants to know how long he must wait to see the moment when all planets are lined up in a row.
After watching the sky closely, Junseo found the following facts.
- There is a moment when the planets are lined up in a row.
- The period of planetary alignment is at most seconds.
- Planets 1, 2, and 3 line up every seconds.
- Planets 2, 3, and 4 line up every seconds.
- ...
- Planets , , and line up every seconds.
Find the period of planetary alignment for Junseo.
Input
The first line contains the number of planets that should be aligned. ()
The second line contains integers , separated by spaces, that give the period at which the planets line up. ()
Output
Print the period of planetary alignment. The period of planetary alignment is at most seconds.