|
試し割法
https://ja.wikipedia.org/wiki/試し割り法
LET N=105000
LET COUNT=1
FOR I=3 TO N STEP 2
LET FL=0
FOR J=3 TO INT(SQR(I))
IF MOD(I,J)=0 THEN
LET FL=1
EXIT FOR
END IF
NEXT J
IF FL=0 THEN
LET COUNT=COUNT+1
IF MOD(COUNT,100)=0 THEN PRINT COUNT;"th prime ";I
END IF
NEXT I
END
-------------------------------------------------------------------------------
LET S=1
DO WHILE S<100
LET S=NEXTPRIME(S)
PRINT S
LOOP
END
EXTERNAL FUNCTION NEXTPRIME(X)
IF X<2 THEN
LET NEXTPRIME=2
EXIT FUNCTION
END IF
IF MOD(X,2)=0 THEN LET X=X+1 ELSE LET X=X+2
DO
LET FL=0
FOR N=3 TO INT(SQR(X))
IF MOD(X,N)=0 THEN
LET FL=1
EXIT FOR
END IF
NEXT N
IF FL=0 THEN
LET NEXTPRIME=X
EXIT FUNCTION
END IF
LET X=X+2
LOOP
END FUNCTION
|
|