Sum of Digits

4.1

14 votes
Dynamic Programming, Hard, Algorithms, Mathematics, Open, Approved
Problem

The problems is to find the count of numbers between A and B (inclusive) that have sum of digits equal to S.

Also print the smallest such number between A and B (inclusive).

Input:

Single line consisting of A,B,S.

Output:

Two lines.

In first line the number of integers between A and B having sum of digits equal to S.

In second line the smallest such number between A and B.

Constraints:

1 <= A <= B < 10^15

1 <= S <= 135

Time Limit: 3
Memory Limit: 256
Source Limit:
Editor Image

?