|
自然数100までの素数(?)を求める
PUBLIC NUMERIC N
LET N=10 !'探索範囲 (+n+ni+nj+nj+nk..)~(-n-ni-nj-nj-nk..) (i,j,k...は虚数単位)
DO
READ L
IF L=0 THEN STOP
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
DATA 0
PRINT L;":";
IF CHECK(L)=1 THEN PRINT "素数"
LOOP
END
EXTERNAL FUNCTION CHECK(L) !'オクトニオン(8元数)探索 (8重ループ)
OPTION BASE 0
DIM X(15),Y(15),Z(15)
LET X(0)=L
FOR H=0 TO N
FOR S8=1 TO -1 STEP -2
LET Y(7)=H*S8
FOR G=0 TO N
FOR S7=1 TO -1 STEP -2
LET Y(6)=G*S7
FOR F=0 TO N
FOR S6=1 TO -1 STEP -2
LET Y(5)=F*S6
FOR E=0 TO N
FOR S5=1 TO -1 STEP -2
LET Y(4)=E*S5
FOR D=0 TO N
FOR S4=1 TO -1 STEP -2
LET Y(3)=D*S4
FOR C=0 TO N
FOR S3=1 TO -1 STEP -2
LET Y(2)=C*S3
FOR B=0 TO N
FOR S2=1 TO -1 STEP -2
LET Y(1)=B*S2
FOR A=0 TO N
FOR S1=1 TO -1 STEP -2
LET Y(0)=A*S1
IF COMP(Y)=0 THEN
CALL CDIV(X,Y,Z)
IF COMP(Z)=0 THEN
LET FR=0
FOR I=0 TO 15
IF FRAC(Z(I))<>0 THEN
LET FR=1
EXIT FOR
END IF
NEXT I
IF FR=0 THEN
PRINT "{";
CALL CPRINT(Y)
PRINT ",";
CALL CPRINT(Z)
PRINT "}"
LET CHECK=0
EXIT FUNCTION !'見つけ次第ループ打ち切り
END IF
END IF
END IF
NEXT S1
NEXT A
NEXT S2
NEXT B
NEXT S3
NEXT C
NEXT S4
NEXT D
NEXT S5
NEXT E
NEXT S6
NEXT F
NEXT S7
NEXT G
NEXT S8
NEXT H
LET CHECK=1
END FUNCTION
EXTERNAL FUNCTION COMP(Y())
OPTION BASE 0
DIM Z(15)
F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0,0,0, 1,0,0,0
!'DATA 0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0
!'DATA 0,0,0,0,0,0,0,0,0,0,0,0,0, 1,0,0
!'DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0
!'DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0, 1,0
!'DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0
!'DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 1
!'DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1
FOR J=0 TO 15
IF Y(J)=Z(J) THEN LET FL=FL+1 !'0,±1,±i,±j,±k...は約数(?)ではない
NEXT J
IF FL=16 THEN
LET COMP=1
EXIT FUNCTION
END IF
NEXT I
LET COMP=0
END FUNCTION
EXTERNAL FUNCTION FRAC(X) !'小数部
LET FRAC=X-INT(X)
END FUNCTION
EXTERNAL SUB CDIV(A(),B(),C())
OPTION BASE 0
DIM BB(15),S(15)
CALL CCONJ(B,BB)
CALL CMUL(B,BB,S)
CALL CMUL(A,BB,C)
MAT C=(1/S(0))*C
END SUB
EXTERNAL SUB CCONJ(A(),B()) !'共役数
LET B(0)=A(0)
FOR I=1 TO 15
LET B(I)=-A(I)
NEXT I
END SUB
EXTERNAL SUB CPRINT(A())
FOR I=0 TO 15
IF A(I)<>0 THEN
IF A(I)<0 THEN
PRINT " - ";
ELSE
IF I>0 THEN PRINT " + ";
END IF
IF ABS(A(I))<>1 OR I=0 THEN PRINT STR$(ABS(A(I)));
IF I>0 THEN PRINT MID$("ijklmnopqrstuvw",I,1);
END IF
NEXT I
END SUB
EXTERNAL SUB CMUL(A(),B(),S())
LET S(0)=A(0)*B(0)-A(1)*B(1)-A(2)*B(2)-A(3)*B(3)-A(4)*B(4)-A(5)*B(5)-A(6)*B(6)-A(7)*B(7)-A(8)*B(8)-A(9)*B(9)-A(10)*B(10)-A(11)*B(11)-A(12)*B(12)-A(13)*B(13)-A(14)*B(14)-A(15)*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3)*B(14)+A(4)*B(9)+A(5)*B(8)+A(6)*B(11)-A(7)*B(10)-A(8)*B(5)-A(9)*B(4)+A(10)*B(7)-A(11)*B(6)+A(12)*B(1)+A(13)*B(0)+A(14)*B(3)-A(15)*B(2)
LET S(14)=A(0)*B(14)-A(1)*B(15)-A(2)*B(12)+A(3)*B(13)+A(4)*B(10)-A(5)*B(11)+A(6)*B(8)+A(7)*B(9)-A(8)*B(6)-A(9)*B(7)-A(10)*B(4)+A(11)*B(5)+A(12)*B(2)-A(13)*B(3)+A(14)*B(0)+A(15)*B(1)
LET S(15)=A(0)*B(15)+A(1)*B(14)-A(2)*B(13)-A(3)*B(12)+A(4)*B(11)+A(5)*B(10)-A(6)*B(9)+A(7)*B(8)-A(8)*B(7)+A(9)*B(6)-A(10)*B(5)-A(11)*B(4)+A(12)*B(3)+A(13)*B(2)-A(14)*B(1)+A(15)*B(0)
END SUB
!EXTERNAL SUB CMUL(A(),B(),C())
!OPTION BASE 0
!DIM T$(15,15)
!MAT C=ZER
!MAT READ T$
!FOR I=0 TO 15
! FOR J=0 TO 15
! IF A(I)<>0 AND B(J)<>0 THEN
! IF T$(I,J)="-0" THEN
! LET C(0)=C(0)-A(I)*B(J)
! ELSE
! LET D=VAL(T$(I,J))
! IF D>=0 THEN
! LET C(D)=C(D)+A(I)*B(J)
! ELSE
! LET C(-D)=C(-D)-A(I)*B(J)
! END IF
! END IF
! END IF
! NEXT J
!NEXT I
!DATA 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 '16元数乗積表
!DATA 1, -0, 3, -2, 5, -4, -7, 6, 9, -8,-11, 10,-13, 12, 15,-14
!DATA 2, -3, -0, 1, 6, 7, -4, -5, 10, 11, -8, -9,-14,-15, 12, 13
!DATA 3, 2, -1, -0, 7, -6, 5, -4, 11,-10, 9, -8,-15, 14,-13, 12
!DATA 4, -5, -6, -7, -0, 1, 2, 3, 12, 13, 14, 15, -8, -9,-10,-11
!DATA 5, 4, -7, 6, -1, -0, -3, 2, 13,-12, 15,-14, 9, -8, 11,-10
!DATA 6, 7, 4, -5, -2, 3, -0, -1, 14,-15,-12, 13, 10,-11, -8, 9
!DATA 7, -6, 5, 4, -3, -2, 1, -0, 15, 14,-13,-12, 11, 10, -9, -8
!DATA 8, -9,-10,-11,-12,-13,-14,-15, -0, 1, 2, 3, 4, 5, 6, 7
!DATA 9, 8,-11, 10,-13, 12, 15,-14, -1, -0, -3, 2, -5, 4, 7, -6
!DATA 10, 11, 8, -9,-14,-15, 12, 13, -2, 3, -0, -1, -6, -7, 4, 5
!DATA 11,-10, 9, 8,-15, 14,-13, 12, -3, -2, 1, -0, -7, 6, -5, 4
!DATA 12, 13, 14, 15, 8, -9,-10,-11, -4, 5, 6, 7, -0, -1, -2, -3
!DATA 13,-12, 15,-14, 9, 8, 11,-10, -5, -4, 7, -6, 1, -0, 3, -2
!DATA 14,-15,-12, 13, 10,-11, 8, 9, -6, -7, -4, 5, 2, -3, -0, 1
!DATA 15, 14,-13,-12, 11, 10, -9, 8, -7, 6, -5, -4, 3, 2, -1, -0
!END SUB
|
|