Sequence: smallest number with exactly n divisors: Difference between revisions
Sequence: smallest number with exactly n divisors (view source)
Revision as of 15:29, 8 June 2019
, 5 years ago→{{header|Phix}}
Line 388:
=={{header|Phix}}==
Using the
<lang Phix>constant limit = iff(machine_bits()=32?58:66)
sequence found = repeat(0,limit)
integer n = 1
procedure populate_found(integer i)
end procedure
for i=1 to limit do
sequence f = factors(i,1)
integer lf = length(f)
if lf<=2 then ri = power(2,i-1) -- prime (or 1)
elsif lf=3 then ri = power(6,f[2]-1) -- p^2 (eg f={1,5,25})▼
▲ ri = power(6,f[2]-1) -- p^2 (eg f={1,5,25})
elsif f[2]>2 -- (see note)
and f[$] = power(f[2],lf-1) then ri = power(product(get_primes(-(lf-1))),f[2]-1) -- p^k (eg f={1,3,9,27})
elsif length(f)=4 then ri = power(2,f[3]-1)*power(3,f[2]-1) -- p*q (eg f={1,2,3,6})▼
else populate_found(i) ri = found[i] -- do the rest manually
▲ end while
▲ ri = power(2,f[3]-1)*power(3,f[2]-1) -- p*q (eg f={1,2,3,6})
▲ while found[i]=0 do
▲ integer k = length(factors(n,1)) -- do the rest manually
▲ if k<=limit and found[k]=0 then
▲ found[k] = n
▲ end if
▲ n += 1
end if
printf(1,"%d->%d\n",{i,ri})
end for</lang>
apparently, but everything seems ok within the
{{out}}
64-bit (as shown) manages 8 more answers than 32-bit, which as per limit halts on 58.
|