Sequence: smallest number with exactly n divisors: Difference between revisions
Sequence: smallest number with exactly n divisors (view source)
Revision as of 07:22, 8 June 2019
, 5 years ago→{{header|Phix}}
(Add Factor example) |
|||
Line 388:
=={{header|Phix}}==
Uses primes[] and add_block() from [[Extensible_prime_generator#Phix|Extensible_prime_generator]]<br>
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)
atom ri
for i=1 to limit do
sequence f
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})
elsif f[2]>2 -- (see note)
and f[$] = power(f[2],lf-1) then
while length(primes)<lf-1 do
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
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 IEE754 53/64 bit limits this imposes.
afaict, it takes longer 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.
<pre>
1->1
2->2
3->4
4->6
5->16
6->12
7->64
8->24
9->36
10->48
11->1024
12->60
13->4096
14->192
15->144
16->120
17->65536
18->180
19->262144
20->240
21->576
22->3072
23->4194304
24->360
25->1296
26->12288
27->900
28->960
29->268435456
30->720
31->1073741824
32->840
33->9216
34->196608
35->5184
36->1260
37->68719476736
38->786432
39->36864
40->1680
41->1099511627776
42->2880
43->4398046511104
44->15360
45->3600
46->12582912
47->70368744177664
48->2520
49->46656
50->6480
51->589824
52->61440
53->4503599627370496
54->6300
55->82944
56->6720
57->2359296
58->805306368
59->288230376151711744
60->5040
61->1152921504606846976
62->3221225472
63->14400
64->7560
65->331776
66->46080
</pre>
=={{header|REXX}}==
|