#GL0000326. Bội số có tổng chữ số nhỏ nhất (Small Multiple)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bội số có tổng chữ số nhỏ nhất (Small Multiple)
Small Multiple
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given a positive integer , consider all positive multiples of , including numbers with arbitrarily many decimal digits. Let be the sum of the digits in the usual decimal representation of a positive integer .
Determine the minimum possible value of among all positive multiples of . Print only the minimum digit sum, not the multiple itself, which may be far too large to store.
Input
One line containing the integer .
Output
Print one integer: the minimum digit sum of a positive multiple of .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
6
Output
3
Explanation
and ; no positive multiple of has a smaller digit sum.
Example 2
Input
41
Output
5
Explanation
has digit sum , and no smaller digit sum is possible.
Example 3
Input
79992
Output
36
Explanation
itself is a positive multiple with digit sum . The remainder-graph shortest path confirms that no smaller sum is achievable.