Equal prime and composite sums: Difference between revisions

m
(Added XPL0 example.)
Line 35:
<lang julia>using Primes
 
function getsequencematches(N, masksize = 10_000_000_000)
pmask = primesmask(Nmasksize)
found, psum, csum, pindex, cindex, pcount, ccount = 0, 2, 4, 2, 4, 1, 1
incrementpsum() = (pindex += 1; if pmask[pindex] psum += pindex; pcount += 1 end)
incrementcsum() = (cindex += 1; if !pmask[cindex] csum += cindex; ccount += 1 end)
while pindexfound < N
while psum < csum
pindex >= Nmasksize && return
incrementpsum()
end
if psum == csum
println("Primes up to $pindex at position $pcount and composites up to $cindex at position $ccount sum to $psum.")
found += 1
while psum == csum
incrementpsum()
Line 58 ⟶ 59:
end
 
@time getsequencematches(500_000_00011)
</lang>{{out}}
<pre>
Line 72 ⟶ 73:
Primes up to 86254457 at position 5012372 and composites up to 21123471 at position 19786181 sum to 209456854921713.
Primes up to 390180569 at position 20840220 and composites up to 91491160 at position 86192660 sum to 3950430820867201.
72.974740 seconds (1.09 G allocations: 19.829 GiB, 0.77% gc time)
</pre>
 
4,102

edits