Sequence: smallest number with exactly n divisors: Difference between revisions
Content added Content deleted
Line 388: | Line 388: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Using the |
Using the various formula from the OEIS:A005179 link above.<br> |
||
get_primes() and product() have 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) |
<lang Phix>constant limit = iff(machine_bits()=32?58:66) |
||
sequence found = repeat(0,limit) |
sequence found = repeat(0,limit) |
||
integer n = 1 |
integer n = 1 |
||
atom ri |
|||
procedure populate_found(integer i) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end procedure |
|||
for i=1 to limit do |
for i=1 to limit do |
||
sequence f = factors(i,1) |
sequence f = factors(i,1) |
||
integer lf = length(f) |
integer lf = length(f) |
||
atom ri |
|||
ri = power(2,i-1) -- prime (or 1) |
if lf<=2 then ri = power(2,i-1) -- prime (or 1) |
||
⚫ | |||
elsif lf=3 then |
|||
⚫ | |||
elsif f[2]>2 -- (see note) |
elsif f[2]>2 -- (see note) |
||
and f[$] = power(f[2],lf-1) then |
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}) |
||
⚫ | |||
while length(primes)<lf-1 do |
|||
else populate_found(i) ri = found[i] -- do the rest manually |
|||
add_block() |
|||
⚫ | |||
ri = power(product(primes[1..lf-1]),f[2]-1) -- p^k (eg f={1,3,9,27}) |
|||
elsif length(f)=4 then |
|||
⚫ | |||
else |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end while |
|||
ri = found[i] |
|||
end if |
end if |
||
printf(1,"%d->%d\n",{i,ri}) |
printf(1,"%d->%d\n",{i,ri}) |
||
end for</lang> |
end for</lang> |
||
Note: the f[2]>2 test should really be something more like >log(primes[lf-1])/log(2), |
|||
apparently, but everything seems ok within the |
apparently, but everything seems ok within the IEEE 754 53/64 bit limits this imposes. |
||
It takes longer, afaict, to print the answers that it did to calculate them, tee hee! |
|||
{{out}} |
{{out}} |
||
64-bit (as shown) manages 8 more answers than 32-bit, which as per limit halts on 58. |
64-bit (as shown) manages 8 more answers than 32-bit, which as per limit halts on 58. |