|
約数を求める
OPTION ARITHMETIC COMPLEX
LET N=10 !'探索範囲
DIM P(-N TO N,-N TO N)
FOR X=0 TO N
FOR Y=0 TO N
LET Z=COMPLEX(X,Y)
PRINT Z;":";
LET FL=0
MAT P=ZER
LET P(0,0)=1 !'0,±1,±iは約数(?)ではない
LET P(1,0)=1
LET P(0,1)=1
LET P(-1,0)=1
LET P(0,-1)=1
IF P(RE(Z),IM(Z))=0 THEN
!'IF ISGAUSSIANPRIME(Z)<>0 THEN
!' PRINT "素数";
!'ELSE
FOR A=0 TO N
FOR B=0 TO N
FOR I=1 TO -1 STEP -2
FOR J=1 TO -1 STEP -2
LET V=COMPLEX(A*I,B*J)
IF V<>0 THEN
LET S=Z/V
IF CMOD(Z,V)=0 AND P(RE(S),IM(S))=0 AND P(RE(V),IM(V))=0 THEN
PRINT "{";V;",";S;"}";
LET P(RE(S),IM(S))=1
LET P(RE(V),IM(V))=1
LET FL=1
END IF
END IF
NEXT J
NEXT I
NEXT B
NEXT A
IF FL=0 THEN PRINT "素数";
!' END IF
END IF
PRINT
NEXT Y
NEXT X
END
EXTERNAL FUNCTION CINT(Z)
OPTION ARITHMETIC COMPLEX
LET CINT=COMPLEX(INT(RE(Z)),INT(IM(Z)))
END FUNCTION
EXTERNAL FUNCTION CMOD(X,Y)
OPTION ARITHMETIC COMPLEX
LET CMOD=X-CINT(X/Y)*Y
END FUNCTION
EXTERNAL FUNCTION ISGAUSSIANPRIME(Z) !'ガウス素数
OPTION ARITHMETIC COMPLEX
LET ISGAUSSIANPRIME=0
LET A = ABS(RE(Z))
LET B = ABS(IM(Z))
IF A = 0 THEN
IF MOD(B, 4) = 3 AND ISPRIME(B)<>0 THEN LET ISGAUSSIANPRIME=-1
END IF
IF B = 0 THEN
IF MOD(A , 4) = 3 AND ISPRIME(A)<>0 THEN LET ISGAUSSIANPRIME=-1
END IF
IF ISPRIME(A*A+B*B)<>0 THEN LET ISGAUSSIANPRIME=-1
END FUNCTION
EXTERNAL FUNCTION ISPRIME(X)
OPTION ARITHMETIC COMPLEX
IF X=0 OR X=1 THEN
LET ISPRIME=0
EXIT FUNCTION
END IF
IF X=2 THEN
LET ISPRIME=-1
EXIT FUNCTION
END IF
IF MOD(X,2)=0 THEN
LET ISPRIME=0
EXIT FUNCTION
END IF
FOR I=3 TO INT(SQR(X)) STEP 2
IF MOD(X,I)=0 THEN
LET ISPRIME=0
EXIT FUNCTION
END IF
NEXT I
LET ISPRIME=-1
END FUNCTION
|
|