#CCBCHBON0000026. Số đầu tiên có tổng chữ số bằng k (First Number With Digit Sum k)
Số đầu tiên có tổng chữ số bằng k (First Number With Digit Sum k)
First Number With Digit Sum k
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given , find the smallest integer in inclusive interval whose decimal digit sum equals , or -1 if absent. The digit sum of 0 is 0. Stop the outer search loop at the first match.
Input
One line contains with and .
Output
Print the smallest matching number, or -1.
Subtasks
-
Subtask 1 (20%): ; .
-
Subtask 2 (30%): ; .
-
Subtask 3 (50%): ; .
Examples
Example 1
Input:
10 20 2
Output:
11
Explanation:
Within [10,20], the first number with digit sum 2 is 11.
Example 2
Input:
0 0 0
Output:
0
Explanation:
Within [0,0], the first number with digit sum 0 is 0.
Example 3
Input:
99 100 50
Output:
-1
Explanation:
Within [99,100], the first number with digit sum 50 is -1.