Statistics

Problem Statement for "Powerful"

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".

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. 1

    Returns: "NOT A PERFECT POWER"

  2. 2000000000

    Returns: "NOT A PERFECT POWER"

  3. 1000000000

    Returns: "10^9"

  4. 999999999

    Returns: "NOT A PERFECT POWER"

  5. 5645376

    Returns: "2376^2"

  6. 16384

    Returns: "2^14"

  7. 1638400

    Returns: "1280^2"

  8. 26873856

    Returns: "72^4"

  9. 675

    Returns: "NOT A PERFECT POWER"

  10. 81

    Returns: "3^4"

  11. 182250000

    Returns: "13500^2"

  12. 729000000

    Returns: "30^6"

  13. 8

    Returns: "2^3"

  14. 4096

    Returns: "2^12"

  15. 1610612736

    Returns: "NOT A PERFECT POWER"

  16. 1018081

    Returns: "1009^2"

  17. 1977326743

    Returns: "7^11"

  18. 1995498241

    Returns: "44671^2"

  19. 2500

    Returns: "50^2"

  20. 1331

    Returns: "11^3"

  21. 536870912

    Returns: "2^29"

  22. 49

    Returns: "7^2"

  23. 90000

    Returns: "300^2"

  24. 225

    Returns: "15^2"

  25. 1000000001

    Returns: "NOT A PERFECT POWER"

  26. 248832

    Returns: "12^5"

  27. 25

    Returns: "5^2"

  28. 104060401

    Returns: "101^4"

  29. 36

    Returns: "6^2"

  30. 4

    Returns: "2^2"

  31. 16

    Returns: "2^4"

  32. 228886642

    Returns: "NOT A PERFECT POWER"

  33. 1999967841

    Returns: "44721^2"

  34. 177147

    Returns: "3^11"

  35. 1999999999

    Returns: "NOT A PERFECT POWER"

  36. 10201

    Returns: "101^2"

  37. 200000

    Returns: "NOT A PERFECT POWER"

  38. 9

    Returns: "3^2"

  39. 2

    Returns: "NOT A PERFECT POWER"

  40. 121

    Returns: "11^2"

  41. 625

    Returns: "5^4"

  42. 1073741824

    Returns: "2^30"

  43. 81000000

    Returns: "9000^2"

  44. 307546875

    Returns: "675^3"

  45. 289

    Returns: "17^2"

  46. 43046721

    Returns: "3^16"

  47. 16777216

    Returns: "2^24"

  48. 8

    Returns: "2^3"

  49. 81

    Returns: "3^4"

    Do NOT return "9^2"

  50. 675

    Returns: "NOT A PERFECT POWER"

  51. 1

    Returns: "NOT A PERFECT POWER"

  52. 2000000000

    Returns: "NOT A PERFECT POWER"


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: