Given prime factors of a number, what is the fastest way to calculate divisors?
clc; clear;
sms=0;
count = 1;
x=0;
for i=11:28123
fac = factor(i);
sm = 1;
for j = 1:length(fac)-1
sm = sm + sum(prod(unique(combntns(fac,j), 'rows'),2));
end
if sm>i
x(count) = i;
count = count + 1;
end
end
sum1=0;
count = 1;
for i=1:length(x)
for j=i:length(x)
smss = x(i) + x(j);
if smss <= 28123
sum1(count) = smss;
count = count + 1;
end
end
end
sum1 = unique(sum1);
disp(28123*28124/2-sum(sum1));
currently I'm using this prod(unique(combntns(fac,j), 'rows'),2)
code which is awfully slow and I'm using Matlab.
Matlab
, but given factorsa_0^k_0 * a_1^k_1 * ... * a_n^k_n
, the sum of the proper divisors is given as(a_0^0 + a_0^1 + ... + a_0^k_0) * (a_1^0 + a_1^1 + ... + a_1^k_1) * ... * (a_n^0 + a_n^1 + ... + a_n^k_n)
, which should be a pretty fast formula to calculate manually. \$\endgroup\$