Heliocentric

0

0 votes
Problem

Nicolaus Copernicus, born in Toruń in the Kingdom of Poland in 1473, was the first to collect sufficient evidence to show that the heliocentric view of the solar system (that the Sun was at the center of the planetary orbits) could compete with the Ptolemaic view (that the Earth was at the center). Copernicus viewed each planet as revolving in a circular orbit with the Sun as the common center of each circle. This new model, which was later improved by many other astronomers, made it much simpler to understand and predict the motions of the planets. Pictured below is his rendering of the planetary orbits.

enter image description here

Consider two of the planets in Copernicus’ orbital system: Earth and Mars. Assume the Earth orbits the Sun in exactly 365 Earth days, and Mars orbits the Sun in exactly 687 Earth days. Thus the Earth’s orbit starts at day 0 and continues to day 364, and then starts over at day 0. Mars orbits similarly, but on a 687 day time scale. We would like to find out how long it will take until both planets are on day 0 of their orbits simultanously. Write a program that can determine this.


Input Format:
The first line of input contains an integer N indicating the number of test cases. N lines follow. Each test case contains two integers E and M. These indicate which days Earth and Mars are at their respective orbits.


Output Format:
For each case, display the case number followed by the smallest number of days until the two planets will both be on day 0 of their orbits. Follow the format of the sample output.


Constraints:
0 ≤ E < 365
0 ≤ M < 687

Time Limit: 2
Memory Limit: 256
Source Limit:
Editor Image

?