Jump to content

Radical of an integer: Difference between revisions

m
Line 179:
78735
</pre>
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">using Formatting, Primes, UnicodePlots
 
radical(n) = prod(map(first, factor(n).pe))
radicallength(n) = length(factor(n).pe)
 
println("The radicals for the first 50 positive integers are:")
foreach(p -> print(rpad(p[2], 4), p[1] % 10 == 0 ? "\n" : ""), enumerate(map(radical, 1:50)))
 
for i in [99999, 499999, 999999]
println("\nRadical for ", format(i, commas=true), ": ", format(radical(i), commas=true))
end
 
println("\nBreakdown of numbers of distinct prime factors for positive integers from 1 to 1,000,000:")
histogram(map(radicallength, 1:1_000_000), nbins = 8)
</syntaxhighlight>{{out}}
<pre>
The radicals for the first 50 positive integers are:
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 for 99,999: 33,333
 
Radical for 499,999: 3,937
 
Radical for 999,999: 111,111
 
Breakdown of numbers of distinct prime factors for positive integers from 1 to 1,000,000:
┌ ┐
[0.0, 1.0) ┤▏ 1
[1.0, 2.0) ┤██████▌ 78 734
[2.0, 3.0) ┤███████████████████████▌ 288 726
[3.0, 4.0) ┤███████████████████████████████ 379 720
[4.0, 5.0) ┤████████████████▉ 208 034
[5.0, 6.0) ┤███▌ 42 492
[6.0, 7.0) ┤▎ 2 285
[7.0, 8.0) ┤▏ 8
└ ┘
Frequency
</pre>
 
 
 
 
 
=={{header|Raku}}==
4,105

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.