Problem Statement
A number is a Perfect Square if it can be expressed as k^2 for some positive integer k. A number is a Perfect Power if it can be expressed as k^n (k to the nth power) for some positive integers k and n, where n and k must both be greater than 1.
Create a class Powerful that contains the method power that takes an int, number, as
input and returns the
Definition
- Class:
- Powerful
- Method:
- power
- Parameters:
- int
- Returns:
- String
- Method signature:
- String power(int number)
- (be sure your method is public)
Notes
- If there is more than one way to express a number as a Perfect Power, your method should express it with the highest exponent possible. (see example 1)
- Your method should return "<k>^<n>"; (quotes and angle brackets for clarity only) with no blanks or leading zeroes.
Constraints
- number is between 1 and 2,000,000,000 inclusive.
Examples
1
Returns: "NOT A PERFECT POWER"
2000000000
Returns: "NOT A PERFECT POWER"
1000000000
Returns: "10^9"
999999999
Returns: "NOT A PERFECT POWER"
5645376
Returns: "2376^2"
16384
Returns: "2^14"
1638400
Returns: "1280^2"
26873856
Returns: "72^4"
675
Returns: "NOT A PERFECT POWER"
81
Returns: "3^4"
182250000
Returns: "13500^2"
729000000
Returns: "30^6"
8
Returns: "2^3"
4096
Returns: "2^12"
1610612736
Returns: "NOT A PERFECT POWER"
1018081
Returns: "1009^2"
1977326743
Returns: "7^11"
1995498241
Returns: "44671^2"
2500
Returns: "50^2"
1331
Returns: "11^3"
536870912
Returns: "2^29"
49
Returns: "7^2"
90000
Returns: "300^2"
225
Returns: "15^2"
1000000001
Returns: "NOT A PERFECT POWER"
248832
Returns: "12^5"
25
Returns: "5^2"
104060401
Returns: "101^4"
36
Returns: "6^2"
4
Returns: "2^2"
16
Returns: "2^4"
228886642
Returns: "NOT A PERFECT POWER"
1999967841
Returns: "44721^2"
177147
Returns: "3^11"
1999999999
Returns: "NOT A PERFECT POWER"
10201
Returns: "101^2"
200000
Returns: "NOT A PERFECT POWER"
9
Returns: "3^2"
2
Returns: "NOT A PERFECT POWER"
121
Returns: "11^2"
625
Returns: "5^4"
1073741824
Returns: "2^30"
81000000
Returns: "9000^2"
307546875
Returns: "675^3"
289
Returns: "17^2"
43046721
Returns: "3^16"
16777216
Returns: "2^24"
8
Returns: "2^3"
81
Returns: "3^4"
Do NOT return "9^2"
675
Returns: "NOT A PERFECT POWER"
1
Returns: "NOT A PERFECT POWER"
2000000000
Returns: "NOT A PERFECT POWER"