

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
高橋君は 個のボールを 人に配ろうとしています。
それぞれの人がボールを 個以上受け取るような配り方の中で、ボールが最も多い人と最も少ない人のボールの個数の差が最大で何個になるか求めてください。
制約
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
出力
ボールの個数の差としてあり得る最大値を出力せよ。
入力例 1Copy
3 2
出力例 1Copy
1
それぞれの人がボールを 個以上受け取るように 個のボールを 人に配る方法は、 人に 個、もう 人に 個配る方法のみです。
よってボールの個数の差の最大値は です。
入力例 2Copy
3 1
出力例 2Copy
0
個のボールを 人に渡すしかなく、この時ボールの個数の差は です。
入力例 3Copy
8 5
出力例 3Copy
3
例えば 人にボールをそれぞれ 個配った場合に、ボールが最も多い人と最も少ない人のボールの個数の差が となり、これが最大です。
Score : points
Problem Statement
Takahashi is distributing balls to persons.
If each person has to receive at least one ball, what is the maximum possible difference in the number of balls received between the person with the most balls and the person with the fewest balls?
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the maximum possible difference in the number of balls received.
Sample Input 1Copy
3 2
Sample Output 1Copy
1
The only way to distribute three balls to two persons so that each of them receives at least one ball is to give one ball to one person and give two balls to the other person.
Thus, the maximum possible difference in the number of balls received is .
Sample Input 2Copy
3 1
Sample Output 2Copy
0
We have no choice but to give three balls to the only person, in which case the difference in the number of balls received is .
Sample Input 3Copy
8 5
Sample Output 3Copy
3
For example, if we give balls to the five persons, the number of balls received between the person with the most balls and the person with the fewest balls would be , which is the maximum result.