|
多角数
https://ja.wikipedia.org/wiki/多角数
FOR N=3 TO 10
PRINT N;"角数"
FOR X=1 TO 10
PRINT X;":";POLYGONALNUMBER(N,X)
NEXT X
PRINT
NEXT N
FOR X=2 TO 100
FOR N=3 TO 20
IF ISPOLYGONALNUMBER(N,X)<>0 THEN PRINT X;":";N;"角数"
NEXT N
NEXT X
END
EXTERNAL FUNCTION POLYGONALNUMBER(N,X) !'N角数
LET POLYGONALNUMBER=((N-2)*X^2-(N-4)*X)/2
END FUNCTION
EXTERNAL FUNCTION ISTRIANGULARNUMBER(X) !'三角数かどうか
LET S=(SQR(8*X+1)-1)/2
IF FP(S)=0 THEN LET ISTRIANGULARNUMBER=1 ELSE LET ISTRIANGULARNUMBER=0
END FUNCTION
EXTERNAL FUNCTION ISPOLYGONALNUMBER(N,M) !'多角数かどうか
LET X1=(SQR(N^2+(8*M-8)*N-16*M+16)+N-4)/(2*N-4)
!'LET X2=(-SQR(N^2+(8*M-8)*N-16*M+16)-N+4)/(2*N-4) !' X2<0
IF FP(X1)=0 THEN LET ISPOLYGONALNUMBER=1 ELSE LET ISPOLYGONALNUMBER=0
END FUNCTION
|
|