We will buy a product for N yen (the currency of Japan) at a shop. If we use only…
- User
We will buy a product for N yen (the currency of Japan) at a shop.
If we use only 1000-yen bills to pay the price, how much change will we receive?
Assume we use the minimum number of bills required.
Constraints
- 1 \leq N \leq 10000
- N is an integer. Input
Input is given from Standard Input in the following format:
N
Output
Print the amount of change as an integer.
Examples
Input
1900
Output
100
Input
3000
Output
0
Assistant
pythonN = int(input()) print((1000 - N % 1000) % 1000)Another approach: The change can be calculated by finding how much more is needed to reach the next multiple of 1000. For example, if N is 1900, then 1900 mod 1000 is 900. 1000 - 900 = 100. But if N is exactly a multiple of 1000, like 3000, then 3000 mod 1000 is 0, so 1000 -0 is 1000, but we need to mod again by 1000 to get 0. Hence, (1000 - N % 1000) % 1000. This avoids the multiplication and division steps. Let's check:
For N=1900: 1900%1000=900. 1000-900=100. mod 1000 is 100. Correct.
For N=3000: 3000%1000=0. 1000-0=1000. mod 1000 is 0. Correct.
For N=500: 500%1000=500. 1000-500=500. mod 1000 is 500. Correct.
N=1: 1%1000=1. 1000-1=999. mod 1000 is 999. Correct.
This method is more concise and efficient. So the code becomes as above.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.