COCI '07 Contest 3 #5 Cudak

View as PDF

Submit solution

Points: 15 (partial)
Time limit: 0.6s
Memory limit: 32M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Božo is a strange little boy. Every day he tires his friends with strange questions. Today's question is: how many integers in the interval [A, B] are there such that the sum of their digits is S, and which is the smallest such number?

Write a program that answers Božo's question so that he can get some sleep.

Input Specification

The input contains three integers A, B and S (1 \le A \le B < 10^{15}, 1 \le S \le 135).

Output Specification

The first line should contain the number of integers in the interval with the digit sum equal to S. The second line should contain the smallest such integer. The input data will guarantee that the first number is at least 1.


For correctly outputting one of the two numbers you will receive 50\% of the score.

Note: if you want to receive credit for just the second number, be sure to output something (0, for example) as the first number so the judge can interpret your output correctly.

Sample Input 1

1 9 5

Sample Output 1


Sample Input 2

1 100 10

Sample Output 2


Sample Input 3

11111 99999 24

Sample Output 3



  • 3
    Plasmatic  commented on Nov. 14, 2018, 6:28 p.m. edit 2

    The test data on this problem is weak, I had a passing solution that would output


    for the data 10 11 1. The correct answer should be


    I have since corrected the mistake in my code though I'm not sure whether my fix works for all cases like that.

  • 2
    Kirito  commented on Oct. 26, 2018, 10:38 p.m.

    Partial scoring has been enabled, and all submissions have been rejudged.