P3409 Daily Duty Monitor and Weekly Duty Monitor
Description
In a semester, there are $n$ daily duty monitors (值日班长), where A is the $m$-th daily duty monitor, and there are $p$ weekly duty monitors (值周班长), where B is the $q$-th weekly duty monitor. Assume we ignore holidays and any other schedule changes, and the daily/weekly duty rotations are never rearranged; that is, every week always has $5$ school days and $2$ rest days, and this semester never ends. On which day of the semester will it first happen that A is the daily duty monitor and B is the weekly duty monitor at the same time? If it never happens, output `Orz mgh!!!`.
Input Format
Multiple test cases. Each test case consists of one line with four integers $n, m, p, q$. It is guaranteed that $m \le n$ and $q \le p$.
Output Format
For each test case, output one line with the result.
Explanation/Hint
| Test point ID | Number of test cases | $n$ | $p$ | Special property |
|:-:|:-:|:-:|:-:|:-:|
| 1 | $\le 10^4$ | $\le 100$ | $\le 100$ | Yes |
| 2 | $\le 100$ | $\le 1000$ | $\le 1000$ | No |
| 3 | $\le 1000$ | $\le 10^4$ | $\le 10^4$ | No |
| 4 | $\le 1000$ | $\le 10^5$ | $\le 10^5$ | Yes |
| 5 | $\le 1000$ | $\le 10^5$ | $\le 10^5$ | No |
| 6 | $\le 1000$ | $\le 10^6$ | $\le 10^6$ | No |
| 7 | $\le 1000$ | $\le 10^7$ | $\le 10^7$ | No |
| 8 | $\le 10^4$ | $\le 10^7$ | $\le 10^7$ | Yes |
| 9 | $\le 1000$ | $\le 10^9$ | $\le 10^9$ | Yes |
| 10 | $\le 1000$ | $\le 10^9$ | $\le 10^9$ | No |
Special property: $n$ is a multiple of $5$.
For $100\%$ of the testdata, $1 \le m \le n \le 10^9$, $1 \le q \le p \le 10^9$, and the number of test cases does not exceed $10^4$. Note that the maximum number of test cases and the maximum values of $n$ and $p$ will not be reached at the same time.
Translated by ChatGPT 5