No.186 Chinese Style (Easy)
タグ : / 解いたユーザー数 336
作問者 :
LayCurse
Problem Statement
In some foreign countries, there seem to be problems with many possible answers, such as ○+□=8, but grading them must be a lot of work, right?
This time, let's try giving it a Chinese-style arrangement.
You are given $3$ integer $2$-tuples $(X_1, Y_1),(X_2, Y_2), (X_3, Y_3)$. Find the positive integer to put in □ that simultaneously satisfies
□ ${\rm mod}\ Y_k = X_k, \quad k=1,2,3$
.
Hmm, wait, this might have many answers.
In that case, find the smallest one.
Input
$X_1$ $Y_1$ $X_2$ $Y_2$ $X_3$ $Y_3$
$0 \leq X_i < Y_i \leq 1000000 = 10^6$
Output
Output the smallest positive integer that fits in □.
However, if none exists, output $\verb|-1|$ instead.
Sample
Sample 1
Input
10 20 10 30 10 40
Output
10
Dividing by $20$, by $30$, or by $40$ all leave a remainder of $10$, so this just has to be $10$.
Sample 2
Input
10 20 10 30 30 40
Output
70
Dividing by $20$ or by $30$ leaves a remainder of $10$, so... oh, it was $70$.
Sample 3
Input
1 2 0 4 5 17
Output
-1
It is not divisible by $2$, so surely it can't be divisible by $4$, can it?
Sample 4
Input
80712 221549 320302 699312 140367 496729
Output
38774484298448350
This sample was added on April 20, 2015 at 00:00.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。