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 |
0) | |
| | 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. |
|
|
1) | |
| | Returns: 1 | No multiplications can be performed. |
|
|
2) | |
| | 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).
|
|
|
3) | |
| |
4) | |
| |
5) | |
| | Returns: -1 | Even if we would only use digit 2 every time, 2^30 has more than 8 digits and overflows the calculator. |
|
|
6) | |
| |
7) | |
| |