Radical of an integer: Difference between revisions

Content added Content deleted
m (→‎{{header|ALGOL 68}}: Fixed note about specifying the heap size)
(PascalABC.NET)
 
Line 2,092: Line 2,092:
Real time: 15.218 s User time: 15.068 s Sys. time: 0.033 s CPU share: 99.23 %
Real time: 15.218 s User time: 15.068 s Sys. time: 0.033 s CPU share: 99.23 %
</pre>
</pre>

=={{header|PascalABC.NET}}==
<syntaxhighlight lang="delphi">
function Factors(N: integer): List<integer>;
begin
var lst := new List<integer>;
var i := 2;
while i * i <= N do
begin
while N.Divs(i) do
begin
if i not in lst then
lst.Add(i);
N := N div i;
end;
i += 1;
end;
if N >= 2 then
lst.Add(N);
Result := lst;
end;

function Radical(x: integer) := Factors(x).Product;

begin
for var i:=1 to 50 do
begin
Write(Radical(i):3);
if i mod 10 = 0 then
Writeln;
end;
Writeln;

Writeln('Radical(99999) = ',Radical(99999));
Writeln('Radical(499999) = ',Radical(499999));
Writeln('Radical(999999) = ',Radical(999999));
Writeln;

var a := |0| *8;
for var i:=1 to 1000000 do
a[Factors(i).Count] += 1;
for var i:=0 to 7 do
Writeln($'{i}: {a[i]}');
end.
</syntaxhighlight>
{{out}}
<pre>
1 2 3 2 5 6 7 2 3 10
11 6 13 14 15 2 17 6 19 10
21 22 23 6 5 26 3 14 29 30
31 2 33 34 35 6 37 38 39 10
41 42 43 22 15 46 47 6 7 10

Radical(99999) = 33333
Radical(499999) = 3937
Radical(999999) = 111111

0: 1
1: 78734
2: 288726
3: 379720
4: 208034
5: 42492
6: 2285
7: 8
</pre>



=={{header|Perl}}==
=={{header|Perl}}==