CiscoOA #14
Count Numbers with Digit Sum
Estimated EasyJudge-ready
Topics (AI-labelled)Bits & MathSimulation
Count the integers in 1..X whose decimal digit sum is exactly Y. The original requires outputting −1, not 0, when no number qualifies.
Input
The input is X Y. The original gave no numeric bounds; this site adds 1≤X≤10^18 and 1≤Y≤162; only positive integers are counted.
Output
Output a single integer, the answer.
Example 1
Input:
20 5
Output:
2
Example 2
Input:
1 2
Output:
-1
Example 3
Input:
10 1
Output:
2
Example notes
The outputs of the three public examples are, in order: 2; -1; 2. Verified by independent enumeration or direct simulation.
Editorial
Loading solution…