多角錐数

 投稿者:しばっち  投稿日:2016年 5月28日(土)20時45分25秒
  多角錐数
https://ja.wikipedia.org/wiki/四角錐数
https://www.wolframalpha.com/input/?i=sum(((n-2)*x%5E2-(n-4)*x)%2F2)

INPUT  PROMPT "N角錐数=":N
FOR M=1 TO 20
   LET S=0
   FOR I=1 TO M
      LET S=S+POLYGONALNUMBER(N,I)
   NEXT I
   PRINT S;PYRAMIDALNUMBER(N,M)
NEXT  M
END

EXTERNAL  FUNCTION POLYGONALNUMBER(N,X) !'N角数
LET POLYGONALNUMBER=((N-2)*X^2-(N-4)*X)/2
END FUNCTION

EXTERNAL  FUNCTION PYRAMIDALNUMBER(N,X)
LET PYRAMIDALNUMBER=X/6*(X+1)*(X*N-2*X-N+5) !'N角錐数
END FUNCTION

------------------------------------------------------------------------

OPTION ARITHMETIC COMPLEX
FOR X=3 TO 200
   FOR N=3 TO 8
      IF ISPYRAMIDALNUMBER(N,X)<>0 THEN
         PRINT X;":";N;"角錐数"
      END IF
   NEXT N
NEXT X
END

EXTERNAL  FUNCTION ISPYRAMIDALNUMBER(N,M) !'N角錐数かどうか
OPTION ARITHMETIC COMPLEX
LET I=SQR(-1)
LET K1 = ((-(SQR(3)*I)/2)-1/2)*(SQR((-4*N^4)+68*N^3-((-972*M^2)+324*M+429)*N^2-(3888*M^2-2268*M-1190)*N+3888*M^2-3888*M-1225)/(2*3^(3/2)*(N-2)^2)+(M*(6*N^2-24*N+24)-N^2+7*N-12)/(2*N^3-12*N^2+24*N-16))^(1/3)+(((SQR(3)*I)/2-1/2)*(N^2-7*N+13))/((3*N^2-12*N+12)*(SQR((-4*N^4)+68*N^3-((-972*M^2)+324*M+429)*N^2-(3888*M^2-2268*M-1190)*N+3888*M^2-3888*M-1225)/(2*3^(3/2)*(N-2)^2)+(M*(6*N^2-24*N+24)-N^2+7*N-12)/(2*N^3-12*N^2+24*N-16))^(1/3))-1/(N-2)
LET K2 = ((SQR(3)*I)/2-1/2)*(SQR((-4*N^4)+68*N^3-((-972*M^2)+324*M+429)*N^2-(3888*M^2-2268*M-1190)*N+3888*M^2-3888*M-1225)/(2*3^(3/2)*(N-2)^2)+(M*(6*N^2-24*N+24)-N^2+7*N-12)/(2*N^3-12*N^2+24*N-16))^(1/3)+(((-(SQR(3)*I)/2)-1/2)*(N^2-7*N+13))/((3*N^2-12*N+12)*(SQR((-4*N^4)+68*N^3-((-972*M^2)+324*M+429)*N^2-(3888*M^2-2268*M-1190)*N+3888*M^2-3888*M-1225)/(2*3^(3/2)*(N-2)^2)+(M*(6*N^2-24*N+24)-N^2+7*N-12)/(2*N^3-12*N^2+24*N-16))^(1/3))-1/(N-2)
LET K3 = (SQR((-4*N^4)+68*N^3-((-972*M^2)+324*M+429)*N^2-(3888*M^2-2268*M-1190)*N+3888*M^2-3888*M-1225)/(2*3^(3/2)*(N-2)^2)+(M*(6*N^2-24*N+24)-N^2+7*N-12)/(2*N^3-12*N^2+24*N-16))^(1/3)+(N^2-7*N+13)/((3*N^2-12*N+12)*(SQR((-4*N^4)+68*N^3-((-972*M^2)+324*M+429)*N^2-(3888*M^2-2268*M-1190)*N+3888*M^2-3888*M-1225)/(2*3^(3/2)*(N-2)^2)+(M*(6*N^2-24*N+24)-N^2+7*N-12)/(2*N^3-12*N^2+24*N-16))^(1/3))-1/(N-2)
IF (FP(ABS(RE(K1)))<1E-8 OR 1-FP(ABS(RE(K1)))<1E-8) AND FP(IM(K1))=0 OR (FP(ABS(RE(K2)))<1E-8 OR 1-FP(ABS(RE(K2)))<1E-8) AND FP(IM(K2))=0 OR (FP(ABS(RE(K3)))<1E-8 OR 1-FP(ABS(RE(K3)))<1E-8) AND FP(IM(K3))=0 THEN LET ISPYRAMIDALNUMBER=1 ELSE LET ISPYRAMIDALNUMBER=0
END FUNCTION
 

戻る