問題一覧 > 通常問題

No.186 Chinese Style (Easy)

レベル : / AI推定難易度 : 1200 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 128 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 336
作問者 : LayCurse
お気に入りにしたユーザー ProblemId : 447 / 自分の提出
問題文最終更新日: 2026-06-25 03:06:45
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 98 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。