Attractive numbers: Difference between revisions

Add PL/I
(Added Algol 68)
(Add PL/I)
Line 2,538:
{{out}}
<pre>4 6 8 10 12 14 15 18 20 21 22 26 27 28 30 32 33 34 35 36 38 39 42 44 45 46 48 50 51 52 55 57 58 62 63 65 66 68 69 70 74 75 76 77 78 80 82 85 86 87 91 92 93 94 95 98 99 100 102 105 106 108 110 111 112 114 115 116 117 118 119 120</pre>
 
=={{header|PL/I}}==
<lang pli>attractive: procedure options(main);
%replace MAX by 120;
declare prime(1:MAX) bit(1);
sieve: procedure;
declare (i, j, sqm) fixed;
prime(1) = 0;
do i=2 to MAX; prime(i) = '1'b; end;
sqm = sqrt(MAX);
do i=2 to sqm;
if prime(i) then do j=i*2 to MAX by i;
prime(j) = '0'b;
end;
end;
end sieve;
factors: procedure(nn) returns(fixed);
declare (f, i, n, nn) fixed;
n = nn;
f = 0;
do i=2 to n;
if prime(i) then do while(mod(n,i) = 0);
f = f+1;
n = n/i;
end;
end;
return(f);
end factors;
attractive: procedure(n) returns(bit(1));
declare n fixed;
return(prime(factors(n)));
end attractive;
declare (i, col) fixed;
i = 0;
col = 0;
call sieve();
do i=2 to MAX;
if attractive(i) then do;
put edit(i) (F(4));
col = col + 1;
if mod(col,18) = 0 then put skip;
end;
end;
end attractive;</lang>
{{out}}
<pre> 4 6 8 9 10 12 14 15 18 20 21 22 25 26 27 28 30 32
33 34 35 38 39 42 44 45 46 48 49 50 51 52 55 57 58 62
63 65 66 68 69 70 72 74 75 76 77 78 80 82 85 86 87 91
92 93 94 95 98 99 102 105 106 108 110 111 112 114 115 116 117 118
119 120</pre>
 
=={{header|PL/M}}==
2,117

edits