Connection Status:
Competition Arena > Powerful
SRM 89 · 2002-05-16 · by dgoodman
Class Name: Powerful
Return Type: String
Method Name: power
Arg Types: (int)
Problem Statement

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 String "<k>^<n>", where <k> to the <n>th power is equal to number. If a number cannot be represented as a Perfect Power, your method should return "NOT A PERFECT POWER".

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
0)
1
Returns: "NOT A PERFECT POWER"
1)
2000000000
Returns: "NOT A PERFECT POWER"
2)
1000000000
Returns: "10^9"
3)
999999999
Returns: "NOT A PERFECT POWER"
4)
5645376
Returns: "2376^2"
48)
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.

Coding Area

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

Submitting as anonymous