TopcoderArchiveVisit Topcoder
TCO14 Nov 2018
2018 TCO Semi 2

NextLuckyNumber

Problem statement, definition, constraints, and public examples.

Problem Statement

Jitka's birthday is coming up and Emanuel is thinking about a present for her. As he is a poor student, he decided to buy her a scratch-off lottery ticket.

Emanuel remembers that Jitka's lucky digit is digit. He also remembers that this is her age-th birthday. Hence, he would like to bring her a ticket whose serial number contains exactly age copies of the digit digit.

The serial number of the last ticket that was already sold is lastTicket. What is the next ticket Emanuel should buy?

Definition

Class:
NextLuckyNumber
Method:
getTicket
Parameters:
long, int, int
Returns:
long
Method signature:
long getTicket(long lastTicket, int age, int digit)
(be sure your method is public)

Constraints

  • lastTicket will be between 1 and (10^17 - 1), inclusive.
  • age will be between 1 and 17, inclusive.
  • digit will be between 0 and 9, inclusive.

Examples

  1. 2048
    3
    0
    Returns: 3000
    The next number with exactly three zeros is 3000.
  2. 47
    9
    2
    Returns: 222222222
  3. 9232425262
    2
    6
    Returns: 9232425266
  4. 7
    1
    2
    Returns: 12
  5. 76
    1
    7
    Returns: 78
    The next number with exactly one digit 7 is the number 78.
Back to all problems