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
47
10
7
Returns: 7
You will write down "47, 57, 67, 7" and stop. The last number you wrote down was 7.98
1
10
Returns: 101
You will write down "98, 99, 100, 101". The last number written down is 101.0
1
7
Returns: 6
123456789
10
5
Returns: 12345
123456789
10
17
Returns: 12345679