#40 What's a Perfect Power anyway?
A perfect power is a classification of positive integers:
In mathematics, a perfect power is a positive integer that can be expressed as an integer power of another positive integer. More formally, n is a perfect power if there exist natural numbers m > 1, and k > 1 such that mk = n.
Your task is to check wheter a given integer is a perfect power. If it is a perfect power, return a pair m and k with mk = n as a proof. Otherwise return Nothing, Nil, null, NULL, None or your language's equivalent.
Note: For a perfect power, there might be several pairs. For example 81 = 3^4 = 9^2, so (3,4) and (9,2) are valid solutions. However, the tests take care of this, so if a number is a perfect power, return any pair that proves it.
Examples
isPerfectPower(4) => new int[]{2,2}
isPerfectPower(5) => null
isPerfectPower(8) => new int[]{2,3}
isPerfectPower(9) => new int[]{3,2}
'매일매일개발 > Codewars' 카테고리의 다른 글
codewars #42 Delete occurrences of an element if it occurs more than n times (6kyu) (0) | 2018.05.16 |
---|---|
codewars #41 Dashatize it (6kyu) (0) | 2018.05.15 |
codewars #39 Help the bookseller ! (6kyu) (1) | 2018.05.10 |
codewars #38 Highest Scoring Word (6kyu) (1) | 2018.05.09 |
codewars #37 Count the smiley faces! (6kyu) (1) | 2018.05.08 |