RosettaCodeData/Task/Legendre-prime-counting-function/REXX/legendre-prime-counting-function-1.rexx
2026-04-30 12:34:36 -04:00

34 lines
534 B
Rexx

-- 21 Feb 2026
include Setting
say 'LEGENDRE PRIME COUNTER (NO MEMOIZATION)'
say version
say
numeric digits 10
do n = 0 to 9
call Time('r')
a = 10**n; p = Pie(a)
say '10^'n Right(p,9) Format(Time('e'),3,3)'s'
end
exit
Pie:
procedure expose Prim. Memo.
arg xx
if xx < 3 then
return 0+(xx=2)
n = Primes(Isqrt(xx))
return Phi(xx,n)+n-1
Phi:
procedure expose Prim.
arg xx,yy
if yy < 2 then
return xx-(xx%2)*(yy=1)
p = Prim.yy
if xx <= p then
return 1
return Phi(xx,yy-1)-Phi(xx%p,yy-1)
-- Primes; Isqrt
include Math