-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfactors_to_n.m
More file actions
42 lines (40 loc) · 1.06 KB
/
factors_to_n.m
File metadata and controls
42 lines (40 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function A = factors_to_n(N)
% This function will return the divisors(including 1 and that no) of all the nos from 2 to N.
% The function primes_to_n.m should be defined in the domain
B = primes_to_n(N);A = zeros(N,2);
bn = length(B);A(1,:) = [1 1];
for i = 1:bn
A(B(1,i),1) = 1;
A(B(1,i),2) = B(1,i);
end
j1 = 1;ind = 1;
for j = 4:N
while ind == 1
if rem(j,B(1,j1)) ==0
ind = 0;
k = j/B(1,j1);
if k == 1
continue
end
ji = 1;ki = 1;
while A(k,ki) ~= 0
A(j,ji) = A(k,ki);
if A(j,ji) == k
break
end
ji = ji +1;
ki = ki +1;
end
for i = 1:ki
p1 = B(1,j1)*A(k,i);
if sum(find(A(j,:) == p1)) == 0
A(j,ji+1) = p1;
ji = ji+1;
end
end
else
j1 = j1 +1;
end
end
j1 = 1;ind = 1;
end