#abc231e. E - Minimal payments
E - Minimal payments
Score : points
问题描述
在Atcoder王国中,有种硬币:日元、日元、、日元硬币。 这里满足条件 ,并且对于任意的 ,都有 是 的倍数。
当仅使用这些硬币支付价值为 日元的商品时,付款及找零所需的最小总硬币数量是多少?
准确地说,当 是大于等于 的整数时,求表示正好 日元所需硬币数量与表示正好 日元所需硬币数量之和的最小值。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There are kinds of coins used in the Kingdom of Atcoder: -yen, -yen, , -yen coins.
Here, holds, and is a multiple of for every .
When paying for a product worth yen using just these coins, what is the minimum total number of coins used in payment and returned as change?
Accurately, when is an integer at least , find the minimum sum of the number of coins needed to represent exactly yen and the number of coins needed to represent exactly yen.
Constraints
- All values in input are integers.
- is a multiple of for every .
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3 87
1 10 100
Sample Output 1
5
If we pay with one -yen coin and receive one -yen coin and three -yen coins as the change, the total number of coins will be .
Sample Input 2
2 49
1 7
Sample Output 2
7
It is optimal to pay with seven -yen coins.
Sample Input 3
10 123456789012345678
1 100 10000 1000000 100000000 10000000000 1000000000000 100000000000000 10000000000000000 1000000000000000000
Sample Output 3
233
update @ 2024/3/10 10:05:01