No.187 Chinese Style (Hard)
タグ : / 解いたユーザー数 179
作問者 :
LayCurse
Problem Statement
In some foreign countries, there seem to be problems with many answers, such as ○+□=8, but grading them must be tough, right?
This time, let's try giving it a Chinese-style arrangement.
You are given $N$ $2$-tuples of integers $(X_1, Y_1),(X_2, Y_2), \ldots ,(X_N, Y_N)$. Find a positive integer to fill in □ that simultaneously satisfies
□ ${\rm mod}\ Y_k = X_k, \quad k=1,2,\ldots,N$
.
Hmm, this may have many answers.
In that case, find the smallest one.
Even the smallest one may be a large number, so report only the remainder of the answer when divided by $10^9+7$.
Input
$N$ $X_1$ $Y_1$ $X_2$ $Y_2$ $\vdots$ $X_N$ $Y_N$
$1 \leq N \leq 1000$
$0 \leq X_i < Y_i \leq 1000000000 = 10^9$
Output
Output the remainder when the smallest positive integer that fits in □ is divided by $10^9+7$.
However, if no such integer exists, output $\verb|-1|$ instead.
Sample
Sample 1
Input
3 10 20 10 30 10 40
Output
10
The remainder is $10$ whether you divide by $20$, by $30$, or by $40$, so this just has to be $10$.
Sample 2
Input
3 10 20 10 30 30 40
Output
70
The remainder is $10$ whether you divide by $20$ or by $30$, so... oh, it was $70$.
Sample 3
Input
3 1 2 0 4 5 17
Output
-1
It is not divisible by $2$, so how could it be divisible by $4$?
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。