A - Ball Distribution Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100100

問題文

高橋君は NN 個のボールを KK 人に配ろうとしています。

それぞれの人がボールを 11 個以上受け取るような配り方の中で、ボールが最も多い人と最も少ない人のボールの個数の差が最大で何個になるか求めてください。

制約

  • 1KN1001 \leq K \leq N \leq 100
  • 入力は全て整数である

入力

入力は以下の形式で標準入力から与えられる。

NN KK

出力

ボールの個数の差としてあり得る最大値を出力せよ。


入力例 1Copy

Copy
3 2

出力例 1Copy

Copy
1

それぞれの人がボールを 11 個以上受け取るように 33 個のボールを 22 人に配る方法は、11 人に 11 個、もう 11 人に 22 個配る方法のみです。

よってボールの個数の差の最大値は 11 です。


入力例 2Copy

Copy
3 1

出力例 2Copy

Copy
0

33 個のボールを 11 人に渡すしかなく、この時ボールの個数の差は 00 です。


入力例 3Copy

Copy
8 5

出力例 3Copy

Copy
3

例えば 55 人にボールをそれぞれ 1,4,1,1,11, 4, 1, 1, 1 個配った場合に、ボールが最も多い人と最も少ない人のボールの個数の差が 33 となり、これが最大です。

Score : 100100 points

Problem Statement

Takahashi is distributing NN balls to KK 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

  • 1KN1001 \leq K \leq N \leq 100
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK

Output

Print the maximum possible difference in the number of balls received.


Sample Input 1Copy

Copy
3 2

Sample Output 1Copy

Copy
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 11.


Sample Input 2Copy

Copy
3 1

Sample Output 2Copy

Copy
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 00.


Sample Input 3Copy

Copy
8 5

Sample Output 3Copy

Copy
3

For example, if we give 1,4,1,1,11, 4, 1, 1, 1 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 33, which is the maximum result.



2025-03-31 (Mon)
11:44:16 +00:00