Skip to content

Instantly share code, notes, and snippets.

Created November 25, 2011 17:27
Show Gist options
  • Save anonymous/1394024 to your computer and use it in GitHub Desktop.
Save anonymous/1394024 to your computer and use it in GitHub Desktop.
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