Skip to content

Instantly share code, notes, and snippets.

@Quby
Forked from anonymous/gist:1394024
Created November 25, 2011 17:31
Show Gist options
  • Save Quby/1394037 to your computer and use it in GitHub Desktop.
Save Quby/1394037 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);
}
program pattern;
var
numbers : array of Integer;
n,i : integer;
sum : longint;
procedure factorize (x : integer);
var i : integer; ok : boolean;
begin
ok := false;
for i := 2 to trunc(sqrt(x)) do begin
if (x mod i) = 0 then begin
ok := true;
inc(numbers[i]);
factorize(x div i);
break;
end;
end;
if not ok then inc(numbers[x]);
end;
begin
write('Введите число n: ');
readln(n);
setLength(numbers, n+1);
for i := 2 to n do begin
factorize(i);
end;
sum := 1;
for i := 2 to n do begin
inc(sum, sum*numbers[i]);
end;
writeln('Количество делителей n!: ', sum);
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment