|
素数個数関数
http://ijmcs.future-in-tech.net/9.2/R-RuizSondow.pdf
PRINT π(1000)
END
EXTERNAL FUNCTION π(N)
FOR J=2 TO INT(N)
LET SS=0
FOR I=1 TO J
LET SS=SS+INT(J/I)-INT((J-1)/I)
NEXT I
LET S=S+(1+INT((2-SS)/J))
NEXT J
LET π=S
END FUNCTION
-------------------------------------------------------
PRINT π(1000)
END
EXTERNAL FUNCTION π(N)
FOR I=2 TO N
LET S=S+ISPRIME(I)
NEXT I
LET π=S
END FUNCTION
EXTERNAL FUNCTION ISPRIME(N)
LET S=1
FOR I=2 TO N-1
LET S=MOD(S*I,N)
NEXT I
IF MOD(S*S,N)=1 THEN
LET ISPRIME=1
ELSE
LET ISPRIME=0
END IF
END FUNCTION
|
|