Jordan-Pólya numbers: Difference between revisions

(Created Nim solution.)
Line 161:
The 3800th Jordan-Pólya number is 7213895789838336
i.e. (4!)^8 * (2!)^16
</pre>
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">""" The aupto() function is taken from the Python code at oeis.org/A001013 """
 
function aupto(lim::T, mx::T = zero(T)) where T <: Integer
lim < 2 && return [one(T)]
v, t = [one(T)], one(T)
mx == 0 && (mx = lim)
for k in 2:mx
t *= k
t > lim && break
append!(v, [t * rest for rest in aupto(lim ÷ t, t)])
end
return unique(sort!(v))
end
 
const factorials = map(factorial, 2:18)
 
function factor_as_factorials(n::T) where T <: Integer
fac_exp = Tuple{Int, Int}[]
for idx in length(factorials):-1:1
m = n
empty!(fac_exp)
for i in idx:-1:1
expo = 0
while m % factorials[i] == 0
expo += 1
m ÷= factorials[i]
end
if expo > 0
push!(fac_exp, (i + 1, expo))
end
end
m == 1 && break
end
return fac_exp
end
 
const superchars = ["\u2070", "\u00b9", "\u00b2", "\u00b3", "\u2074",
"\u2075", "\u2076", "\u2077", "\u2078", "\u2079"]
super(n::Integer) = prod([superchars[i + 1] for i in reverse(digits(n))])
 
arr = aupto(2^53)
 
println("First 50 Jordan–Pólya numbers:")
foreach(p -> print(rpad(p[2], 6), p[1] % 10 == 0 ? "\n" : ""), enumerate(arr[1:50]))
 
println("\nThe largest Jordan–Pólya number before 100 million: ", arr[findlast(<(100_000_000), arr)])
 
for n in [800, 1800, 2800, 3800]
print("\nThe $(n)th Jordan-Pólya number is: $(arr[n])\n= ")
println(join(map(t -> "($(t[1])!)$(super(t[2])))", factor_as_factorials(arr[n])), " x "))
end
</syntaxhighlight>{{out}}
<pre>
First 50 Jordan–Pólya numbers:
1 2 4 6 8 12 16 24 32 36
48 64 72 96 120 128 144 192 216 240
256 288 384 432 480 512 576 720 768 864
960 1024 1152 1296 1440 1536 1728 1920 2048 2304
2592 2880 3072 3456 3840 4096 4320 4608 5040 5184
 
The largest Jordan–Pólya number before 100 million: 99532800
 
The 800th Jordan-Pólya number is: 18345885696
= (4!)⁷) x (2!)²)
 
The 1800th Jordan-Pólya number is: 9784472371200
= (6!)²) x (4!)²) x (2!)¹⁵)
 
The 2800th Jordan-Pólya number is: 439378587648000
= (14!)¹) x (7!)¹)
 
The 3800th Jordan-Pólya number is: 7213895789838336
= (4!)⁸) x (2!)¹⁶)
</pre>
 
4,102

edits