An integer n is a 'perfect power' if it can be written as a^b for integers a >= 2 and b >= 2. Some numbers have more than one such representation (e.g. 64 = 2^6 = 4^3 = 8^2); to make the answer unique, always use the representation with the LARGEST possible exponent b (equivalently, the smallest possible base a).
Given n, output a^b (literally with a caret) for the representation with the largest exponent, or NONE if n is not a perfect power.
Line 1: a single integer n.
Either a string of the form a^b, or the string NONE.
Example 1
Input
64
Expected
2^6
Explanation
64 = 2^6 = 4^3 = 8^2; the largest exponent is 6, so the answer is 2^6.
Example 2
Input
15
Expected
NONE
Explanation
15 cannot be written as a^b for any integers a>=2, b>=2, so the answer is NONE.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →