TopcoderArchiveVisit Topcoder
TCO13 Apr 2020
TCO20 Parallel 2B

FixedNumberOfDigits

Problem statement, definition, constraints, and public examples.

Problem Statement

You are writing down numbers in increasing order, starting with start and increasing by step. You stop after writing down numberOfDigits digits total. You stop immediately, even if it's in the middle of a number.

Calculate and return the last number you wrote.

Definition

Class:
FixedNumberOfDigits
Method:
sum
Parameters:
int, int, long
Returns:
long
Method signature:
long sum(int start, int step, long numberOfDigits)
(be sure your method is public)

Constraints

  • start will be between 0 and 10^9, inclusive.
  • step will be between 1 and 10, inclusive.
  • numberOfDigits will be between 1 and 10^16, inclusive.

Examples

  1. 47
    10
    7
    Returns: 7
    You will write down "47, 57, 67, 7" and stop. The last number you wrote down was 7.
  2. 98
    1
    10
    Returns: 101
    You will write down "98, 99, 100, 101". The last number written down is 101.
  3. 0
    1
    7
    Returns: 6
  4. 123456789
    10
    5
    Returns: 12345
  5. 123456789
    10
    17
    Returns: 12345679
Back to all problems