#P11059. [入门赛 #27] 数字 (Hard Ver.)
[入门赛 #27] 数字 (Hard Ver.)
Background
If I say I will not stop until I kiss you
Who can force me to settle
——Li Ronghao, "Bu Jiang Jiu"
In life, you cannot just “settle”. Whether you have made the best choice depends on each person.
Problem Description
You need to find an -digit number that satisfies the following two conditions:
-
- The remainder of (the sum of digits of ) divided by is as small as possible.
-
- After condition 1 is satisfied, the value of is as small as possible.
Sum of digits: the total obtained by adding the digits in every position of a number. For example, the sum of digits of is .
Input Format
The input consists of one line with two integers .
Output Format
Output one integer, representing the answer to the problem above.
3 8
107
1 1
1
5 3
10002
2 7
16
Hint
Sample Explanation #1
Three-digit numbers include . Among them, the sum of digits of is , and the remainder of divided by is .
Constraints
For of the testdata, , ;
For of the testdata, , 。
Translated by ChatGPT 5