Problem Statement
You have a calculator that can only handle numbers with up to d digits. Initially, the number shown on the screen is 1. You must perform exactly op multiplication operations. Each operation multiplies the number on the screen by a digit between 2 and 9, inclusive. The result of each operation must be a number with d or less digits. Return the largest number that can be displayed on the screen after op operations. If there is no way to perform op operations without overflowing the calculator, return -1.
Definition
- Class:
- ProdCalc
- Method:
- highest
- Parameters:
- int, int
- Returns:
- long
- Method signature:
- long highest(int d, int op)
- (be sure your method is public)
Constraints
- d will be between 2 and 8, inclusive.
- op will be between 0 and 30, inclusive.
Examples
4
3
Returns: 729
The calculator can store up to 4 digits. With 3 multiplications, we can obtain at most 729, by using digit 9 every time: 1 * 9 * 9 * 9 = 729.8
0
Returns: 1
No multiplications can be performed.2
3
Returns: 98
The storage is limited to 2 digits. The highest number that can be shown on screen after 3 multiplications is 98 (2 * 7 * 7).8
10
Returns: 99574272
8
20
Returns: 99532800
8
30
Returns: -1
Even if we would only use digit 2 every time, 2^30 has more than 8 digits and overflows the calculator.2
6
Returns: 96
3
1
Returns: 9