Coprime triplets: Difference between revisions

Added XPL0 example.
(Added 11l)
(Added XPL0 example.)
Line 1,194:
 
Found 36 such numbers.
</pre>
 
=={{header|XPL0}}==
<lang XPL0>func GCD(N, D); \Return the greatest common divisor of N and D
int N, D, R; \numerator and denominator
[if D > N then
[R:= D; D:= N; N:= R]; \swap D and N
while D > 0 do
[R:= rem(N/D);
N:= D;
D:= R;
];
return N;
]; \GCD
 
int A(50), N, I, J;
 
func Used; \Return 'true' if N is in array A
[for J:= 0 to I-1 do
if A(J) = N then return true;
return false;
];
 
[A(0):= 1; A(1):= 2;
Text(0, "1 2 ");
I:= 2;
for N:= 3 to 50-1 do
if not Used and
GCD(A(I-2), N) = 1 and
GCD(A(I-1), N) = 1 then \coprime
[A(I):= N; I:= I+1;
IntOut(0, N); ChOut(0, ^ );
N:= 3;
];
]</lang>
 
{{out}}
<pre>
1 2 3 5 4 7 9 8 11 13 6 17 19 10 21 23 16 15 29 14 25 27 22 31 35 12 37 41 18 43 47 20 33 49 26 45
</pre>
772

edits