QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100 Difficulty: [show] Hackable ✓

#13843. Xiao Kai's Confusion

Statistics

Xiao Kai has two types of coins with different denominations, both of which are positive integers and coprime. Xiao Kai has an infinite number of each type of coin. Without the possibility of receiving change, there are some items that Xiao Kai cannot pay for exactly using only these two types of coins. Now, Xiao Kai wants to know the value of the most expensive item that he cannot pay for exactly. Note: The input guarantees that such an item exists.

Input

The input consists of a single line containing two integers $a$ and $b$, separated by a space, representing the denominations of the coins Xiao Kai has.

Output

The output consists of a single integer $N$, representing the value of the most expensive item that Xiao Kai cannot pay for exactly without receiving change.

Examples

Input 1

3 7

Output 1

11

Note

Xiao Kai has an infinite number of coins with denominations 3 and 7. Without receiving change, he cannot pay exactly for items with values 1, 2, 4, 5, 8, and 11. Among these, the most expensive item has a value of 11. Items more expensive than 11 can all be purchased, for example: $12 = 3 \times 4 + 7 \times 0$ $13 = 3 \times 2 + 7 \times 1$ $14 = 3 \times 0 + 7 \times 2$ $15 = 3 \times 5 + 7 \times 0$ ...

Input 2

4 5

Output 2

11

Constraints

For 30% of the data: $1 \le a, b \le 50$.

For 60% of the data: $1 \le a, b \le 10,000$.

For 100% of the data: $1 \le a, b \le 1,000,000,000$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.