Created
February 2, 2016 09:01
-
-
Save giannispan/7f7fb568631b1b36157b to your computer and use it in GitHub Desktop.
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, None or your language's equivalent.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isPP = function(n){ | |
var result=[]; | |
for (var m=2; m<=Math.sqrt(n); m++) | |
{ | |
var k = 2; | |
var p = Math.pow(m, k); | |
while (p<=n && p>0) | |
{ | |
if (p==n) | |
result.push(m,k); | |
k++; | |
p = Math.pow(m, k); | |
} | |
} | |
while (result.length > 0) { | |
return result; | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment