#P3951. The Frobenius Coin Problem

    ID: 17199 Type: Default 1000ms 256MiB

The Frobenius Coin Problem

The Frobenius Coin Problem

Little Kai has an unlimited supply of coins in two distinct denominations which are coprime positive integers. Without the possibility of giving change, there are some amounts for which an exact payment cannot be made using just these two coins. Your task is to determine the maximum value that cannot be paid exactly using these coins. Note that the input guarantees that there exists at least one value which cannot be paid exactly.

Mathematical Formulation:

Given two coprime integers \(a\) and \(b\), the largest amount that cannot be paid exactly is given by the formula:

\(a \times b - a - b\)

inputFormat

The input consists of a single line containing two space-separated positive integers \(a\) and \(b\) which are coprime. It is guaranteed that there exists at least one unreachable amount.

outputFormat

Output a single integer, the maximum amount that cannot be paid exactly using the coins of denominations \(a\) and \(b\).

sample

3 5
7