Connection Status:
Competition Arena > FixedNumberOfDigits
TCO20 Round 2B · 2020-04-13 · by misof · Greedy, Simple Math, Simple Search, Iteration
Class Name: FixedNumberOfDigits
Return Type: long
Method Name: sum
Arg Types: (int, int, long long)
Problem Statement

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.

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
0)
47
10
7
Returns: 7

You will write down "47, 57, 67, 7" and stop. The last number you wrote down was 7.

1)
98
1
10
Returns: 101

You will write down "98, 99, 100, 101". The last number written down is 101.

2)
0
1
7
Returns: 6
3)
123456789
10
5
Returns: 12345
4)
123456789
10
17
Returns: 12345679

Submissions are judged against all 173 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class FixedNumberOfDigits with a public method long long sum(int start, int step, long long numberOfDigits) · 173 test cases · 2 s / 256 MB per case

Submitting as anonymous