|
しばっちさんへのお返事です。
ありがとうございます。BASIC Acc で、高速でした。
--------------------------------------------
OPTION ARITHMETIC NATIVE !2進モード
LET t0=TIME
LET K=13
LET KK=2^K
DIM P(K)
MAT READ P
DATA 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97
DIM D(0 TO KK),E(0 TO KK)
FOR J=1 TO 2^K-1
LET T=J
LET S=1
LET B=-1
FOR I=1 TO K
IF MOD(T,2)=1 THEN
LET S=S*P(I)
LET B=-B
END IF
LET T=INT(T/2)
LET FL=0
FOR L=0 TO N
IF D(L)=S AND E(L)=B THEN
LET FL=1
EXIT FOR
END IF
NEXT L
IF FL=0 THEN
LET N=N+1
LET D(N)=S
LET E(N)=B
END IF
NEXT I
NEXT J
CALL QUICKSORT(1,N,D,E)
!書き出し
OPEN #1:NAME "E:\prime_k_13.txt",RECTYPE INTERNAL
ERASE #1
FOR DD=2 TO N
! PRINT E(DD);"*";D(DD)
WRITE #1:D(DD)
NEXT DD
CLOSE #1
PRINT TIME-t0;"秒で計算しました"
END
EXTERNAL SUB QUICKSORT(FI,LA,D(),E())
LET X=D((FI+LA)/2)
LET I=FI
LET J=LA
DO
DO WHILE D(I)<X
LET I=I+1
LOOP
DO WHILE X<D(J)
LET J=J-1
LOOP
IF I>=J THEN EXIT DO
SWAP D(I),D(J)
SWAP E(I),E(J)
LET I=I+1
LET J=J-1
LOOP
IF FI<I-1 THEN CALL QUICKSORT(FI,I-1,D,E)
IF J+1<LA THEN CALL QUICKSORT(J+1,LA,D,E)
END SUB
-------------------------------------------
!新しい?素数判定
OPTION ARITHMETIC RATIONAL !有理数モード
LET k=13 !DATA読み込み
LET k9=8191 !DATAの数
DIM A(k9)
OPEN #2:NAME "E:\prime_k_13.txt",ACCESS INPUT
FOR i=1 TO k9
INPUT #2: A(i)
NEXT i
CLOSE #2
LET f=1
FOR n=1 TO k9
LET f=f*A(n)
NEXT n
DIM P(k+1)
MAT READ P
DATA 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97
PRINT "k=";STR$(k)&":(";STR$(P(k))&")(";STR$(k)&"th prime)"
LET count=14
FOR n=P(k) TO P(k+1)^2-1
LET z=n/f
!PRINT n;":";z
IF n=NUMER(z) THEN
PRINT count;":";n
LET count=count+1
END IF
NEXT n
END
http://blogs.yahoo.co.jp/donald_stinger
|
|