Sequence of primorial primes: Difference between revisions

Content added Content deleted
(Add Factor example)
Line 2,511: Line 2,511:
{{out}}
{{out}}
<pre>1 2 3 4 5 6 11 13 24 66 68 75 167 171 172 287 310 352 384 457</pre>
<pre>1 2 3 4 5 6 11 13 24 66 68 75 167 171 172 287 310 352 384 457</pre>

=={{header|Phix}}==
Horribly slow...
Uses primes[] and add_block() from [[Extensible_prime_generator#Phix|Extensible_prime_generator]]
and Miller_Rabin() from [[Miller–Rabin_primality_test#Phix|Miller–Rabin_primality_test]]
<lang Phix>while length(primes)<100 do add_block() end while

integer primorial = 1
constant integer base = iff(machine_bits()=32?1000:1000000000)
constant integer digits_per = length(sprint(base-1))
constant string dpfmt = sprintf("%%0%dd",digits_per)
-- start at the back, number grows to the right (like little endian)
sequence bigint = {primorial}
atom result

procedure bi_mul(integer pn)
integer carry = 0
for i=1 to length(bigint) do
result = pn*bigint[i]+carry
carry = floor(result/base)
bigint[i] = result-carry*base
end for
while carry <> 0 do
result = carry
carry = floor(carry/base)
bigint &= result-carry*base
end while
end procedure

procedure bi_add(integer carry)
for i=1 to length(bigint) do
result = bigint[i]+carry
carry = floor(result/base)
bigint[i] = result-carry*base
if carry=0 then return end if
end for
if carry!=0 then
if carry<0
or carry!=floor(carry/base) then
?9/0 -- sanity check
end if
bigint &= carry
end if
end procedure

integer found = 0
for n=1 to 100 do
bi_mul(primes[n])
sequence save_bigint = bigint
for pm1=-1 to 2 by 3 do -- (ie n-1 then n+1)
bi_add(pm1)
string bis = sprint(bigint[$])
for i=length(bigint)-1 to 1 by -1 do
bis &= sprintf(dpfmt,bigint[i])
end for
printf(1,"working [%d]...\r",{n})
if Miller_Rabin(bis,1)=PROBABLY_PRIME then
if length(bis)>20 then
bis = sprintf("[big (%d digits)]",length(bis))
end if
printf(1,"%d (%s) is a primorial prime\n",{n,bis})
found += 1
exit
end if
end for
bigint = save_bigint
if found>=12 then exit end if
end for</lang>
{{out}}
<pre>
1 (3) is a primorial prime
2 (5) is a primorial prime
3 (29) is a primorial prime
4 (211) is a primorial prime
5 (2309) is a primorial prime
6 (30029) is a primorial prime
11 (200560490131) is a primorial prime
13 (304250263527209) is a primorial prime
24 ([big (35 digits)]) is a primorial prime
66 ([big (131 digits)]) is a primorial prime
68 ([big (136 digits)]) is a primorial prime
75 ([big (154 digits)]) is a primorial prime
</pre>


=={{header|Python}}==
=={{header|Python}}==