Powerful
SRM 89 · 2002-05-16 · by dgoodman
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
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.
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"
81 Returns: "3^4"
Do NOT return "9^2"
Submissions are judged against all 52 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Powerful with a public method string power(int number) · 52 test cases · 2 s / 256 MB per case