Legendre prime counting function: Difference between revisions
m
use the precalculated values from Nim example
m (→{{header|Julia}}: add trans from nim) |
m (use the precalculated values from Nim example) |
||
Line 2,060:
{{trans|Nim}}
<syntaxhighlight lang="julia">
const masks = [1, 2, 4, 8, 16, 32, 64, 128]
function countprimes(n::Integer)▼
n < 3 && return typeof(n)(n > 1)▼
rtlmt = isqrt(n)
mxndx = (rtlmt - 1) ÷ 2
sqri = (i + i) * (i + 1)
sqri > mxndx && break
bp = i +
for
cullbuf[rci >> 3 + 1] & masks[rci & 7 + 1] != 0 && continue
end
nri
si =
for pm in (rtlmt ÷ bp - 1)
c =
e
while si
end
▲ m = mxndx
▲ c = smalls[k >> 1 + 1] - npc
▲ ee = (k * bp) >> 1
▲ while m >= ee
▲ smalls[m + 1] -= c
▲ m -= 1
▲ end
▲ end
▲ mxri = ri - 1
▲ npc += 1
end
end
ans = larges[1] + ((rilmt + 2*(nbps-1)) * (rilmt - 1) ÷ 2)
▲ result -= larges[i]
end
for ri in 1:typemax(UInt32)
p = roughs[ri + 1]
▲ for j in 1:mxri
▲ p = roughs[j + 1]
m = n ÷ p
for sri in ri+1:ei
end
▲ result -= (ee - j) * (npc + j - 1)
end
return
end
|