Created
November 3, 2017 20:33
-
-
Save Ni55aN/bc4f2ac219fb413c23e281a0aa833e6c to your computer and use it in GitHub Desktop.
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
function primeFactors(n){ | |
var list = []; | |
var maxi=9999999; | |
var maxk=99; | |
for(var i=2;n>1;i++){ | |
var m = null; | |
for(var k=1;;k++){ | |
var d = n/Math.pow(i,k); | |
if(d%1!==0) break; | |
m = k; | |
} | |
if(m){ | |
list.push({i,m}); | |
n/=Math.pow(i,m) | |
} | |
} | |
return list.map(o => o.m==1?'('+o.i+')':'('+o.i+'**'+o.m+')').join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment