Created
November 25, 2011 17:27
-
-
Save anonymous/1394024 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 factorize (x) { | |
for (var i = 2 ; i <= Math.sqrt(x) ; i++) { | |
if (x % i === 0) return [i].concat(factorize(x/i)); | |
} | |
return [x]; | |
} | |
function f (x) { | |
var numbers = []; | |
var nof = []; | |
for (var i = 2 ; i <= x ; i++) { | |
var n = factorize(i); | |
for (var t = 0 ; t < n.length ; t++) { | |
if (numbers.indexOf(n[t]) > -1) { | |
nof[numbers.indexOf(n[t])]++ | |
} else { | |
numbers.push(n[t]); | |
nof.push(1); | |
} | |
} | |
} | |
return nof.reduce(function (s, n) { | |
return s + s*n; | |
}, 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment