-
-
Save Quby/1394037 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); | |
} |
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
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