Problem Statement |
| A number is called a perfect power if it can be written in the form m^k, where m and k are positive integers, and k > 1.
Given two positive integers A and B, find the two perfect powers between A and B, inclusive, that are closest to each other, and return the absolute difference between them. If less than two perfect powers exist in the interval, return -1 instead. |
|
Definition |
| Class: | PerfectPowers | Method: | nearestCouple | Parameters: | long, long | Returns: | long | Method signature: | long nearestCouple(long A, long B) | (be sure your method is public) |
|
|
|
|
Notes |
- | 1 is a perfect power. |
|
Constraints |
- | A will be between 1 and 10^18, inclusive. |
- | B will be between A+1 and 10^18, inclusive. |
|
Examples |
0) | |
| | Returns: 3 | 1 and 4 are the first pair of perfect powers. |
|
|
1) | |
| | Returns: 1 | 8 and 9 are the closest pair of perfect powers. |
|
|
2) | |
| | Returns: -1 | No pair of perfect powers is present in the interval. |
|
|
3) | |
| | Returns: 1 | This is the largest possible range, and 8 and 9 are the closest pair of perfect powers. |
|
|
4) | |
| |