-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathco_primes1.m
More file actions
41 lines (35 loc) · 844 Bytes
/
co_primes1.m
File metadata and controls
41 lines (35 loc) · 844 Bytes
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
function c = co_primes1(m)
%Returns the no of co-primes lesser than the given no.
%global PRI
%PRI= primes_to_n(1000000);
A = prime_factors_dist(m);
[ an am ] = size(A);
P = 1:m;
for i = 1:am
j = 1;
while j <= size(P,2)
if rem(P(1,j),A(1,i)) == 0
P(:,j) = [ ];
else
j = j+1;
end
end
end
P
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
function A = prime_factors_dist(m)
% This function returns the matrix with all the prime factors the no
% posseses. This function returns the distinct factors
%The function primes_to_n should be defined in the directory
B = primes_to_n(m);
k = m;
i = 1;
A = [];
while k > 1
if rem(k, B(1,i)) == 0
k = k / B(1,i);
A = [A B(1,i)];
else
i = i + 1;
end
end