Jordan-Pólya numbers: Difference between revisions

Content added Content deleted
m (→‎Version2: typo)
(J draft)
Line 22: Line 22:


__TOC__
__TOC__

=={{header|J}}==
<syntaxhighlight lang=J>P=: p:i.100x
F=: !P

jpfct=: {{ 2}.!x:i.>.!inv 1+y }}
jpprm=: P{.~F I. 1+]

isjp=: {{
if. 2>y do. y
elseif. 0 < #(q:y)-.jpprm y do. 0
else. +./isjp(#~ ] = <.) (%jpfct) y
end.
}}"0

showjp=: {{
if. 2>y do. i.0 return. end.
F=. f{~1 i:~b #inv isjp Y#~b=. (]=<.) Y=. y%f=. jpfct y
F,showjp y%F
}}</syntaxhighlight>

Task:
<syntaxhighlight lang=J> 5 10$I.isjp i.10000
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
<:^:(0=isjp)^:_]1e8
99532800
showjp 99532800
720 720 24 2 2 2</syntaxhighlight>

Note that jp factorizations are not necessarily unique. For example, <tt>120 120 6 6 6 2 2 2 2 2</tt> would also be a jp factorization of <tt>99532800</tt>.


=={{header|jq}}==
=={{header|jq}}==