問題一覧 > 通常問題

No.3498 Modulo Equation

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 212
作問者 : Naru820 / テスター : Nzt3 toka0428 Solalyth
お気に入りにしたユーザー ProblemId : 13060 / 自分の提出
問題文最終更新日: 2026-04-17 21:22:46
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
CPCTF 2026: PPC (順位表) の他の問題:

Problem Statement

You are given positive integers $A,B$. Here, it is guaranteed that $A > B$.

Find the smallest positive integer $x$ such that the remainder when $x$ is divided by $A$ equals the remainder when $B$ is divided by $x$.

It can be proved that, under the constraints, at least one positive integer $x$ satisfying the condition exists, and moreover that its minimum value is at most $10^5$.

Constraints

  • $1\le B < A \le 300$
  • All inputs are integers

Input

The input is given from standard input in the following format.

$A\ B$

Output

Print on one line the minimum possible value of an integer satisfying the condition.

Sample

Sample 1
Input
5 3
Output
8

The remainder when $8$ is divided by $5$ and the remainder when $3$ is divided by $8$ are both $3$, so $x = 8$ satisfies the condition.

Also, it can be seen that $x = 1,2,3,4,5,6,7$ do not satisfy the condition. Therefore, the answer is $8$.

Sample 2
Input
31 4
Output
35
Sample 3
Input
202 6
Output
208

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。