Jump to content

Sequence: smallest number with exactly n divisors: Difference between revisions

m
Line 388:
 
=={{header|Phix}}==
Using the formulaevarious formula from the OEIS:A005179 link above.<br>
Uses primes[]get_primes() and add_blockproduct() fromhave recently been added as new builtins, if necessary see [[Extensible_prime_generator#Phix|Extensible_prime_generator]], and [[Deconvolution/2D%2B#Phix]].
product() has recently been added as a new builtin, if you need it see [[Deconvolution/2D%2B#Phix]].
<lang Phix>constant limit = iff(machine_bits()=32?58:66)
sequence found = repeat(0,limit)
integer n = 1
 
atom ri
procedure populate_found(integer i)
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 while
end procedure
 
for i=1 to limit do
sequence f = factors(i,1)
integer lf = length(f)
ifatom lf<=2 thenri
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})
elsif lf=3 then
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})
while length(primes)<lf-1 do
else populate_found(i) ri = found[i] -- do the rest manually
add_block()
end while
ri = power(product(primes[1..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
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 while
ri = found[i]
end if
printf(1,"%d->%d\n",{i,ri})
end for</lang>
noteNote: the f[2]>2 test should really be something more like >log(primes[lf-1])/log(2),
apparently, but everything seems ok within the IEE754IEEE 754 53/64 bit limits this imposes.
afaict, itIt takes longer, afaict, to print the answers that it did to calculate them, tee hee!
{{out}}
64-bit (as shown) manages 8 more answers than 32-bit, which as per limit halts on 58.
7,820

edits

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