Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
发一段Mathematica程序代码已经接近完美了,循环的判断条件的最后一个是多余的,为的是不让最后输出时因递归深度过大而跳出。怎样设置递归深度无限? \!\(Pell[D_Integer] := Which[IntegerQ[\@D] == True, "\<No Solution!\>", IntegerQ[\@D] == False, \((Module[{a, P, Q, p, q}, {P[1] \ = 0; \[IndentingNewLine]Q[1] = 1; \[IndentingNewLine]a[1] = IntegerPart[\@D]; \ \[IndentingNewLine]P[2] = a[1]; \[IndentingNewLine]Q[2] = D - a[ 1]\^2; \[IndentingNewLine]P[n_Integer] := \(P[n] = a[n - 1]*Q[n - 1] - P[n - 1]\); \[IndentingNewLine]Q[n_Integer] := \(Q[n] = \(D - P[n]\^2\)\ \/Q[n - 1]\); \[IndentingNewLine]a[n_Integer] := \(a[n] = IntegerPart[\(a[1] + P[n]\)\/Q[ n]]\); \[IndentingNewLine]q[1] = 1; \[IndentingNewLine]p[1] = a[ 1]; \[IndentingNewLine]q[ 2] = a[2]; \[IndentingNewLine]p[2] = a[2]*a[1] + 1; \[IndentingNewLine]p[n_Integer] := \(p[n] = a[n]*p[n - 1] + p[n - 2]\); \[IndentingNewLine]q[ n_Integer] := \(q[n] = a[n]*q[n - 1] + q[ n - 2]\); \[IndentingNewLine]For[i = 1, \((Q[i + 1] ≠ 1 || \ IntegerQ[i\/2] == False)\) && p[i] ≠ q[ i], \(i++\)]; \[IndentingNewLine]x -> p[i], y -> q[ i]\[IndentingNewLine]}\[IndentingNewLine]]\[IndentingNewLine])\ \)\[IndentingNewLine]]\) Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator