Problem 1003: Armageddon
(ACM S.E. U.S.A. Regional 2003, problem 3)
Description
A minor cult, the Earthbound Research in Astrology Union, ERAU, has discovered a solar system
in a distant galaxy. ERAU believes that on the day this solar system was created, from the
viewpoint of the inhabitants of the capital city of its only inhabited planet, the sun and all of the
other planets were perfectly aligned in the sky (making a straight line). ERAU also believes that
this alignment of planets is very meaningful and that the next time that the sun and all of the
planets appear to be perfectly aligned again, the universe will end.
You must write a program that works out how long the universe has to live (assuming that ERAU's
belief is correct). It will receive as input the time it takes (in earth days) for each planet to return to
its original position as viewed from the capital city. (Fortunately, all of the planets take an integral
number of days to return to their original apparent positions, and the sun appears to orbit the world
exactly once per day). It should then determine the number of days it will take for the sun and
planets to all return to their original aligned position. Unfortunately, ERAU isn't sure how many
planets there are, so they've asked you to write a program to check a number of different possible
configurations.
Input Format
The input to the program will consist of a sequence of solar-system specifications. Each begins
with a single line containing a single integer n, 0 < n <= 50, being the number of visible planets in
that solar system. There will then be n lines, each containing a single integer ti,
1 <= ti <= 1,000,000,
which is the time it takes planet i to complete one apparent orbit about the world.
A solar-system specification with 0 planets is the indication of the end of the input. This line
should not be processed.
Output Format
If the planets will realign in 2,147,483,647 days or fewer, your program should print the line
w: THE WORLD ENDS IN d DAYS
where w is replaced by the solar-system number (the first is 1), and d is replaced by the number
days until the end of creation.
If the planets will not realign in the next 2,147,483,647 days, your program should print the line:
w: NOT TO WORRY
where w is replaced by the solar-system number.
Sample Input
4
10
5
15
3
2
1000
3
4
2029
777
6263
7559
1
1
0
Sample Output
1: THE WORLD ENDS IN 30 DAYS
2: THE WORLD ENDS IN 3000 DAYS
3: NOT TO WORRY
4: THE WORLD ENDS IN 1 DAYS
End of Problem