#P3951. [NOIP 2017 提高组] 小凯的疑惑

    ID: 1635 远端评测题 1000ms 250MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>数学2017NOIp 提高组不定方程中国剩余定理,CRT构造

[NOIP 2017 提高组] 小凯的疑惑

Description

Xiaokai has two coin denominations, both positive integers and coprime. He has infinitely many coins of each denomination. Without making change, using only these two denominations, there are some item prices he cannot pay exactly. Now Xiaokai wants to know: among the prices that cannot be paid exactly, what is the most expensive price?

Note: The input guarantees that there exists an item that Xiaokai cannot pay exactly.

Input Format

Two positive integers aa and bb, separated by a single space, representing the denominations of Xiaokai's coins.

Output Format

A single positive integer NN, the most expensive item price that cannot be paid exactly without making change.

3 7
11

Hint

[Explanation for Sample 1]

Xiaokai has infinitely many coins with denominations 33 and 77. Without making change, he cannot pay exactly for items priced 1,2,4,5,8,111, 2, 4, 5, 8, 11. Among them, the most expensive price is 1111. Every price greater than 1111 can be paid, for example:

12=3×4+7×012 = 3 \times 4 + 7 \times 0

13=3×2+7×113 = 3 \times 2 + 7 \times 1

14=3×0+7×214 = 3 \times 0 + 7 \times 2

15=3×5+7×015 = 3 \times 5 + 7 \times 0

Constraints

For 30%30\% of the testdata: 1a,b501 \le a,b \le 50

For 60%60\% of the testdata: 1a,b1041 \le a,b \le 10^4

For 100%100\% of the testdata: 1a,b1091 \le a,b \le 10^9

Translated by ChatGPT 5