|
素数の末尾3桁をcount
----------------------------------------
1億まで
----------------------------------------
!Sieve of Sundaram
DECLARE EXTERNAL FUNCTION cut
OPTION ARITHMETIC NATIVE !2進モード
SET BITMAP SIZE 640*3+1,641 ! x,y軸方向にデフォルトの3倍拡張
SET WINDOW -10,1001,-130,120 !x,y
DRAW grid(20,10)
SET LINE COLOR 2
LET k6=5761455
DIM Ba(k6)
DIM Pa(1000)
LET t0=TIME
LET k9=1E8/2
DIM A(k9)
FOR i=1 TO SQR(k9)
FOR j=i TO INT(k9/3)
LET S=i+j+2*i*j
IF s>k9 THEN GOTO 10
LET A(S)=1
NEXT j
10 NEXT i
LET Ba(1)=2
LET C=1
FOR n=1 TO k9
IF A(n)=0 THEN
LET C=C+1
LET Ba(c)=n*2+1
END IF
NEXT n
FOR n=26 TO k6
LET m4=Ba(n)
LET p4=cut(m4)
LET PA(p4)=PA(p4)+1
NEXT n
FOR n=1 TO 1000
IF PA(n)<>0 THEN
PRINT n;TAB(7);PA(n);TAB(16);PA(n)-14404
LET z=z+PA(n)
PLOT LINES:n,PA(n)-14404;
END IF
NEXT n
PLOT LINES
PRINT z+25
LET TM=TIME-t0
PRINT USING"####." & REPEAT$("#",2):TM;
PRINT "秒"
END
EXTERNAL FUNCTION cut(m)
OPTION ARITHMETIC NATIVE
LET a$=""&STR$(m)
LET L= VAL(RIGHT$(a$,3))
LET cut=L
END FUNCTION
かなり振動してます。
http://blogs.yahoo.co.jp/donald_stinger
|
|