| 2, 3, 4, 3, 21 | => | 2, 3, 4, 3, 21 | => | 2, 3, 4, 3 , 21 | <br/> | 3, 1, 6, 2, 17 | => | 0, 7, 0, 5, 29 | => | 0, 7, 0, 5 , 29 | <br/> | 1, 3, 2, 1, 12 | => | 0, -3,0, 1, -3 | => | 0, 0, 0, -22, -66 | <br/>html
<div style="font-family: Arial; font-size: 13; color: gainsboro; background: #1e1e1e;"> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">rowLength</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">GetLength</span><span class="punctuation">(</span><span class="number" style="color:#b5cea8;">0</span><span class="punctuation">);</span><span class="comment" style="color:#57a64a;">//行數</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">colLength</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">GetLength</span><span class="punctuation">(</span><span class="number" style="color:#b5cea8;">1</span><span class="punctuation">);</span><span class="comment" style="color:#57a64a;">//列數</span><br/> <br/> <span class="keyword" style="color:#569cd6;">for</span> <span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="local name">mainCol</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">mainCol</span> <span class="operator" style="color:#b4b4b4;"><</span> <span class="identifier - local name - (TRANSIENT)">colLength</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">)</span> <span class="comment" style="color:#57a64a;">//按照列,一列一列的消元</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">mainRow</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">;</span> <span class="comment" style="color:#57a64a;">//主元行=主元列</span><br/> <br/> <span class="keyword" style="color:#569cd6;">for</span> <span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="local name">row</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">mainRow</span> <span class="operator" style="color:#b4b4b4;">+</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">row</span> <span class="operator" style="color:#b4b4b4;"><</span> <span class="identifier - local name - (TRANSIENT)">rowLength</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">row</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">)</span> <span class="comment" style="color:#57a64a;">// 從主元的下一行開始 行循環</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">row</span> <span class="operator" style="color:#b4b4b4;">>=</span> <span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">colLength</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">))</span><br/> <span class="keyword" style="color:#569cd6;">break</span><span class="punctuation">;</span><br/> <span class="comment" style="color:#57a64a;">/*<br/> n1*X + n2*Y = a <br/> m1*X + m2*Y = b <br/> => n1*m1*X + n2*m1Y = a*m1<br/> => m1*n1*X + m2*n1*Y = b*n1<br/> */</span><br/> <span class="comment" style="color:#57a64a;">//若是主元參數爲0( 找出此列不爲0的行) 運用行相加 變換0參數</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">mainRow</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">for</span> <span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="local name">rowi</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">mainRow</span> <span class="operator" style="color:#b4b4b4;">+</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">rowi</span> <span class="operator" style="color:#b4b4b4;"><</span> <span class="identifier - local name - (TRANSIENT)">rowLength</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">rowi</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">rowi</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">!=</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">for</span> <span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="local name">colj</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">colj</span> <span class="operator" style="color:#b4b4b4;"><</span> <span class="identifier - local name - (TRANSIENT)">colLength</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">colj</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">mainRow</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">colj</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">+=</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">rowi</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">colj</span><span class="punctuation">];</span><br/> <span class="punctuation">}</span><br/> <span class="keyword" style="color:#569cd6;">break</span><span class="punctuation">;</span><br/> <span class="punctuation">}</span><br/> <span class="punctuation">}</span><br/> <span class="punctuation">}</span><br/> <br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">)</span><br/> <span class="keyword" style="color:#569cd6;">continue</span><span class="punctuation">;</span> <span class="comment" style="color:#57a64a;">//當前行 此列已是0 繼續消元下一行</span><br/> <br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">m</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - method name - (TRANSIENT)">GetMinCommonMultiple</span><span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">],</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">]);</span><br/> <br/> <span class="keyword" style="color:#569cd6;">int</span> <span class="local name">factorMain</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">m</span> <span class="operator" style="color:#b4b4b4;">/</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">];</span><span class="comment" style="color:#57a64a;">//主列的因子 </span><br/> <span class="keyword" style="color:#569cd6;">int</span> <span class="local name">factor</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">m</span> <span class="operator" style="color:#b4b4b4;">/</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">];</span> <span class="comment" style="color:#57a64a;">//待消元列因子</span><br/> <br/> <span class="keyword" style="color:#569cd6;">for</span> <span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="local name">colk</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">colk</span> <span class="operator" style="color:#b4b4b4;"><</span> <span class="identifier - local name - (TRANSIENT)">colLength</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">colk</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">colk</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">colk</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">*</span> <span class="identifier - local name - (TRANSIENT)">factorMain</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">colk</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">*</span> <span class="identifier - local name - (TRANSIENT)">factor</span><span class="punctuation">;</span><br/> <span class="punctuation">}</span><br/> <span class="punctuation">}</span><br/> <span class="punctuation">}</span></div>數組
<div style="font-family: Arial; font-size: 13; color: gainsboro; background: #1e1e1e;"> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> </span><span class="xml doc comment - delimiter" style="color:#608b4e;"><</span><span class="xml doc comment - name" style="color:#608b4e;">summary</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></span><br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> 解不定方程</span><br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> </span><span class="xml doc comment - delimiter" style="color:#608b4e;"></</span><span class="xml doc comment - name" style="color:#608b4e;">summary</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></span><br/> <span class="keyword" style="color:#569cd6;">public</span> <span class="keyword" style="color:#569cd6;">static</span> <span class="keyword" style="color:#569cd6;">bool</span> <span class="method name">ResoveIndefiniteEquation</span><span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span><span class="punctuation">[]</span> <span class="parameter name">arr</span><span class="punctuation">,</span> <span class="keyword" style="color:#569cd6;">int</span> <span class="parameter name">value</span><span class="punctuation">,</span> <span class="keyword" style="color:#569cd6;">int</span> <span class="parameter name">startIndex</span><span class="punctuation">,</span> <span class="keyword" style="color:#569cd6;">ref</span> <span class="keyword" style="color:#569cd6;">int</span><span class="punctuation">[]</span> <span class="parameter name">result</span><span class="punctuation">,</span> <span class="keyword" style="color:#569cd6;">ref</span> <span class="keyword" style="color:#569cd6;">int</span> <span class="parameter name">count</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="identifier - parameter name - (TRANSIENT)">count</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">;</span><span class="comment" style="color:#57a64a;">//遞歸計數,防止無限遞歸</span><br/> <br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">arr</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="keyword" style="color:#569cd6;">null</span> <span class="operator" style="color:#b4b4b4;">||</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - property name - (TRANSIENT)">Length</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">)</span><br/> <span class="keyword" style="color:#569cd6;">return</span> <span class="keyword" style="color:#569cd6;">false</span><span class="punctuation">;</span><br/> <br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - property name - (TRANSIENT)">Length</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">reValue</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - parameter name - (TRANSIENT)">value</span> <span class="operator" style="color:#b4b4b4;">/</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="number" style="color:#b5cea8;">0</span><span class="punctuation">];</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">value</span> <span class="operator" style="color:#b4b4b4;">%</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="number" style="color:#b5cea8;">0</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="number" style="color:#b5cea8;">0</span> <span class="operator" style="color:#b4b4b4;">&&</span> <span class="identifier - local name - (TRANSIENT)">reValue</span> <span class="operator" style="color:#b4b4b4;">>=</span> <span class="constant name - identifier - (TRANSIENT)">MinResove</span> <span class="operator" style="color:#b4b4b4;">&&</span> <span class="identifier - local name - (TRANSIENT)">reValue</span> <span class="operator" style="color:#b4b4b4;"><=</span> <span class="constant name - identifier - (TRANSIENT)">MaxResove</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="identifier - parameter name - (TRANSIENT)">result</span><span class="punctuation">[</span><span class="identifier - parameter name - (TRANSIENT)">startIndex</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">reValue</span><span class="punctuation">;</span><br/> <span class="keyword" style="color:#569cd6;">return</span> <span class="keyword" style="color:#569cd6;">true</span><span class="punctuation">;</span><br/> <span class="punctuation">}</span><br/> <span class="keyword" style="color:#569cd6;">return</span> <span class="keyword" style="color:#569cd6;">false</span><span class="punctuation">;</span><br/> <span class="punctuation">}</span><br/> <br/> <span class="comment" style="color:#57a64a;">//獲取第二部分元的最大公約數</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">commonDivisor</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="number" style="color:#b5cea8;">1</span><span class="punctuation">];</span><br/> <span class="keyword" style="color:#569cd6;">for</span> <span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="local name">i</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">i</span> <span class="operator" style="color:#b4b4b4;"><</span> <span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - property name - (TRANSIENT)">Length</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">);</span> <span class="identifier - local name - (TRANSIENT)">i</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="identifier - local name - (TRANSIENT)">commonDivisor</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - method name - (TRANSIENT)">GetCommonDivisor</span><span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">commonDivisor</span><span class="punctuation">,</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">i</span> <span class="operator" style="color:#b4b4b4;">+</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">]);</span><br/> <span class="punctuation">}</span><br/> <br/> <span class="keyword" style="color:#569cd6;">for</span> <span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="local name">i</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="constant name - identifier - (TRANSIENT)">MinResove</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">i</span> <span class="operator" style="color:#b4b4b4;"><=</span> <span class="constant name - identifier - (TRANSIENT)">MaxResove</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">i</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">currValue</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - parameter name - (TRANSIENT)">value</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="identifier - local name - (TRANSIENT)">i</span> <span class="operator" style="color:#b4b4b4;">*</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="number" style="color:#b5cea8;">0</span><span class="punctuation">];</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">currValue</span> <span class="operator" style="color:#b4b4b4;">%</span> <span class="identifier - local name - (TRANSIENT)">commonDivisor</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">newArr</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="keyword" style="color:#569cd6;">new</span> <span class="keyword" style="color:#569cd6;">int</span><span class="punctuation">[</span><span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - property name - (TRANSIENT)">Length</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">];</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Array</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">Copy</span><span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">,</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">newArr</span><span class="punctuation">,</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">,</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - property name - (TRANSIENT)">Length</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">);</span><br/> <br/> <span class="identifier - parameter name - (TRANSIENT)">result</span><span class="punctuation">[</span><span class="identifier - parameter name - (TRANSIENT)">startIndex</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">i</span><span class="punctuation">;</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">currArr</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - method name - (TRANSIENT)">ResoveIndefiniteEquation</span><span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">newArr</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">currValue</span><span class="punctuation">,</span> <span class="identifier - parameter name - (TRANSIENT)">startIndex</span> <span class="operator" style="color:#b4b4b4;">+</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">,</span> <span class="keyword" style="color:#569cd6;">ref</span> <span class="identifier - parameter name - (TRANSIENT)">result</span><span class="punctuation">,</span> <span class="keyword" style="color:#569cd6;">ref</span> <span class="identifier - parameter name - (TRANSIENT)">count</span><span class="punctuation">);</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">currArr</span><span class="punctuation">)</span><br/> <span class="keyword" style="color:#569cd6;">return</span> <span class="keyword" style="color:#569cd6;">true</span><span class="punctuation">;</span><br/> <br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">count</span> <span class="operator" style="color:#b4b4b4;">></span> <span class="number" style="color:#b5cea8;">1000000</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">"遞歸太深沒法求解"</span><span class="punctuation">);</span><br/> <span class="keyword" style="color:#569cd6;">return</span> <span class="keyword" style="color:#569cd6;">false</span><span class="punctuation">;</span><br/> <span class="punctuation">}</span><br/> <span class="punctuation">}</span><br/> <span class="punctuation">}</span><br/> <span class="keyword" style="color:#569cd6;">return</span> <span class="keyword" style="color:#569cd6;">false</span><span class="punctuation">;</span><br/> <span class="punctuation">}</span></div>ide
<div style="font-family: Arial; font-size: 13; color: gainsboro; background: #1e1e1e;"> <span class="keyword" style="color:#569cd6;">public</span> <span class="keyword" style="color:#569cd6;">class</span> <span class="class name" style="color:#4ec9b0;">GaussHelper</span><br/> <span class="punctuation">{</span><br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> </span><span class="xml doc comment - delimiter" style="color:#608b4e;"><</span><span class="xml doc comment - name" style="color:#608b4e;">summary</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></span><br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> 不定方程解的最小值</span><br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> </span><span class="xml doc comment - delimiter" style="color:#608b4e;"></</span><span class="xml doc comment - name" style="color:#608b4e;">summary</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></span><br/> <span class="keyword" style="color:#569cd6;">private</span> <span class="keyword" style="color:#569cd6;">const</span> <span class="keyword" style="color:#569cd6;">int</span> <span class="constant name">MinResove</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">;</span><br/> <br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> </span><span class="xml doc comment - delimiter" style="color:#608b4e;"><</span><span class="xml doc comment - name" style="color:#608b4e;">summary</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></span><br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> 不定方程解的最大值</span><br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> </span><span class="xml doc comment - delimiter" style="color:#608b4e;"></</span><span class="xml doc comment - name" style="color:#608b4e;">summary</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></span><br/> <br/> <span class="keyword" style="color:#569cd6;">private</span> <span class="keyword" style="color:#569cd6;">const</span> <span class="keyword" style="color:#569cd6;">int</span> <span class="constant name">MaxResove</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="number" style="color:#b5cea8;">100</span><span class="punctuation">;</span><br/> <br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> </span><span class="xml doc comment - delimiter" style="color:#608b4e;"><</span><span class="xml doc comment - name" style="color:#608b4e;">summary</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></span><br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> 利用高斯消元求解一元屢次方程組</span><br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> </span><span class="xml doc comment - delimiter" style="color:#608b4e;"></</span><span class="xml doc comment - name" style="color:#608b4e;">summary</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></span><br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> </span><span class="xml doc comment - delimiter" style="color:#608b4e;"><</span><span class="xml doc comment - name" style="color:#608b4e;">param</span><span class="xml doc comment - attribute name" style="color:#c8c8c8;"> name</span><span class="xml doc comment - delimiter" style="color:#608b4e;">=</span><span class="xml doc comment - attribute quotes" style="color:#c8c8c8;">"</span><span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="xml doc comment - attribute quotes" style="color:#c8c8c8;">"</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></</span><span class="xml doc comment - name" style="color:#608b4e;">param</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></span><br/> <span class="keyword" style="color:#569cd6;">public</span> <span class="keyword" style="color:#569cd6;">static</span> <span class="keyword" style="color:#569cd6;">int</span><span class="operator" style="color:#b4b4b4;">?</span><span class="punctuation">[]</span> <span class="method name">ResoveGauss</span><span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span><span class="punctuation">[,]</span> <span class="parameter name">arr</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">arr</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="keyword" style="color:#569cd6;">null</span><span class="punctuation">)</span> <span class="keyword" style="color:#569cd6;">throw</span> <span class="keyword" style="color:#569cd6;">new</span> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">ArgumentNullException</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">"arr"</span><span class="punctuation">);</span><br/> <br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">rowLength</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">GetLength</span><span class="punctuation">(</span><span class="number" style="color:#b5cea8;">0</span><span class="punctuation">);</span><span class="comment" style="color:#57a64a;">//行數</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">colLength</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">GetLength</span><span class="punctuation">(</span><span class="number" style="color:#b5cea8;">1</span><span class="punctuation">);</span><span class="comment" style="color:#57a64a;">//列數</span><br/> <br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">colLength</span> <span class="operator" style="color:#b4b4b4;"><</span> <span class="number" style="color:#b5cea8;">2</span><span class="punctuation">)</span> <span class="keyword" style="color:#569cd6;">throw</span> <span class="keyword" style="color:#569cd6;">new</span> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">IndexOutOfRangeException</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">"arr.GetLength(1)的值必須大於等於2"</span><span class="punctuation">);</span><br/> <br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">result</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="keyword" style="color:#569cd6;">new</span> <span class="keyword" style="color:#569cd6;">int</span><span class="operator" style="color:#b4b4b4;">?</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">colLength</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">];</span><br/><span class="preprocessor keyword" style="color:#9b9b9b;">#if</span> <span class="identifier">DEBUG</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">"解一元屢次方程:"</span><span class="punctuation">);</span><br/> <span class="identifier - method name - (TRANSIENT)">PrintArr</span><span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">);</span><br/><span class="preprocessor keyword" style="color:#9b9b9b;">#endif</span><br/> <br/> <span class="keyword" style="color:#569cd6;">for</span> <span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="local name">mainCol</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">mainCol</span> <span class="operator" style="color:#b4b4b4;"><</span> <span class="identifier - local name - (TRANSIENT)">colLength</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">)</span> <span class="comment" style="color:#57a64a;">//按照列,一列一列的消元</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">mainRow</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">;</span> <span class="comment" style="color:#57a64a;">//主元行=主元列</span><br/> <br/> <span class="keyword" style="color:#569cd6;">for</span> <span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="local name">row</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">mainRow</span> <span class="operator" style="color:#b4b4b4;">+</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">row</span> <span class="operator" style="color:#b4b4b4;"><</span> <span class="identifier - local name - (TRANSIENT)">rowLength</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">row</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">)</span> <span class="comment" style="color:#57a64a;">// 從主元的下一行開始 行循環</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">row</span> <span class="operator" style="color:#b4b4b4;">>=</span> <span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">colLength</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">))</span><br/> <span class="keyword" style="color:#569cd6;">break</span><span class="punctuation">;</span><br/> <span class="comment" style="color:#57a64a;">/*<br/> n1*X + n2*Y = a <br/> m1*X + m2*Y = b <br/> => n1*m1*X + n2*m1Y = a*m1<br/> => m1*n1*X + m2*n1*Y = b*n1<br/> */</span><br/> <span class="comment" style="color:#57a64a;">//若是主元參數爲0( 找出此列不爲0的行) 運用行相加 變換0參數</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">mainRow</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">for</span> <span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="local name">rowi</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">mainRow</span> <span class="operator" style="color:#b4b4b4;">+</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">rowi</span> <span class="operator" style="color:#b4b4b4;"><</span> <span class="identifier - local name - (TRANSIENT)">rowLength</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">rowi</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">rowi</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">!=</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">for</span> <span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="local name">colj</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">colj</span> <span class="operator" style="color:#b4b4b4;"><</span> <span class="identifier - local name - (TRANSIENT)">colLength</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">colj</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">mainRow</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">colj</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">+=</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">rowi</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">colj</span><span class="punctuation">];</span><br/> <span class="punctuation">}</span><br/> <span class="keyword" style="color:#569cd6;">break</span><span class="punctuation">;</span><br/> <span class="punctuation">}</span><br/> <span class="punctuation">}</span><br/> <span class="punctuation">}</span><br/> <br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">)</span><br/> <span class="keyword" style="color:#569cd6;">continue</span><span class="punctuation">;</span> <span class="comment" style="color:#57a64a;">//當前行 此列已是0 繼續消元下一行</span><br/> <br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">m</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - method name - (TRANSIENT)">GetMinCommonMultiple</span><span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">],</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">]);</span><br/> <br/> <span class="keyword" style="color:#569cd6;">int</span> <span class="local name">factorMain</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">m</span> <span class="operator" style="color:#b4b4b4;">/</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">];</span><span class="comment" style="color:#57a64a;">//主列的因子 </span><br/> <span class="keyword" style="color:#569cd6;">int</span> <span class="local name">factor</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">m</span> <span class="operator" style="color:#b4b4b4;">/</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">];</span> <span class="comment" style="color:#57a64a;">//待消元列因子</span><br/> <br/> <span class="keyword" style="color:#569cd6;">for</span> <span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="local name">colk</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">colk</span> <span class="operator" style="color:#b4b4b4;"><</span> <span class="identifier - local name - (TRANSIENT)">colLength</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">colk</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">colk</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">mainCol</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">colk</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">*</span> <span class="identifier - local name - (TRANSIENT)">factorMain</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">colk</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">*</span> <span class="identifier - local name - (TRANSIENT)">factor</span><span class="punctuation">;</span><br/> <span class="punctuation">}</span><br/> <span class="punctuation">}</span><br/><span class="preprocessor keyword" style="color:#9b9b9b;">#if</span> <span class="identifier">DEBUG</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">rowLength</span> <span class="operator" style="color:#b4b4b4;">></span> <span class="identifier - local name - (TRANSIENT)">mainCol</span> <span class="operator" style="color:#b4b4b4;">+</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">)</span><br/> <span class="identifier - method name - (TRANSIENT)">PrintArr</span><span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">);</span><br/><span class="preprocessor keyword" style="color:#9b9b9b;">#endif</span><br/> <span class="punctuation">}</span><br/> <br/> <span class="comment" style="color:#57a64a;">//回代過程 </span><br/> <span class="comment" style="color:#57a64a;">//回代行 判斷 行數是否大於列數減-1 取到能夠計算結果的回代行</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">backRow</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">rowLength</span> <span class="operator" style="color:#b4b4b4;">></span> <span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">colLength</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">)</span> <span class="operator" style="color:#b4b4b4;">?</span> <span class="identifier - local name - (TRANSIENT)">colLength</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="number" style="color:#b5cea8;">1</span> <span class="operator" style="color:#b4b4b4;">:</span> <span class="identifier - local name - (TRANSIENT)">rowLength</span><span class="punctuation">;</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">backRowIndex</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">backRow</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">;</span><br/> <br/> <span class="comment" style="color:#57a64a;">//回代行的結果值</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">backValue</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">backRowIndex</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">colLength</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">];</span><br/> <br/> <span class="comment" style="color:#57a64a;">//判斷消解行 有多少個變元 ,存儲 變元的 索引</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">listColIndex</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="keyword" style="color:#569cd6;">new</span> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">List</span><span class="punctuation"><</span><span class="keyword" style="color:#569cd6;">int</span><span class="punctuation">>();</span><br/> <span class="keyword" style="color:#569cd6;">for</span> <span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="local name">col</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">col</span> <span class="operator" style="color:#b4b4b4;"><</span> <span class="identifier - local name - (TRANSIENT)">colLength</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">col</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">backRowIndex</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">col</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">!=</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="identifier - local name - (TRANSIENT)">listColIndex</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">Add</span><span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">col</span><span class="punctuation">);</span><br/> <span class="punctuation">}</span><br/> <span class="punctuation">}</span><br/> <br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">listColIndex</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - property name - (TRANSIENT)">Count</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">)</span><br/> <span class="keyword" style="color:#569cd6;">return</span> <span class="keyword" style="color:#569cd6;">null</span><span class="punctuation">;</span><br/> <br/> <span class="comment" style="color:#57a64a;">//根據須要求解的個數 解不定方程處理</span><br/> <br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">listColIndex</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - property name - (TRANSIENT)">Count</span> <span class="operator" style="color:#b4b4b4;">></span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">resoveArr</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">listColIndex</span><span class="operator" style="color:#b4b4b4;">.</span><span class="extension method name - identifier - (TRANSIENT)">Select</span><span class="punctuation">(</span><span class="parameter name">x</span> <span class="operator" style="color:#b4b4b4;">=></span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">backRowIndex</span><span class="punctuation">,</span> <span class="identifier - parameter name - (TRANSIENT)">x</span><span class="punctuation">])</span><span class="operator" style="color:#b4b4b4;">.</span><span class="extension method name - identifier - (TRANSIENT)">ToArray</span><span class="punctuation">();</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">resoveResultArr</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="keyword" style="color:#569cd6;">new</span> <span class="keyword" style="color:#569cd6;">int</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">listColIndex</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - property name - (TRANSIENT)">Count</span><span class="punctuation">];</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">count</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">;</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">flag</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - method name - (TRANSIENT)">ResoveIndefiniteEquation</span><span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">resoveArr</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">backValue</span><span class="punctuation">,</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">,</span> <span class="keyword" style="color:#569cd6;">ref</span> <span class="identifier - local name - (TRANSIENT)">resoveResultArr</span><span class="punctuation">,</span> <span class="keyword" style="color:#569cd6;">ref</span> <span class="identifier - local name - (TRANSIENT)">count</span><span class="punctuation">);</span><br/><span class="preprocessor keyword" style="color:#9b9b9b;">#if</span> <span class="identifier">DEBUG</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">();</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">"--解不定方程"</span><span class="punctuation">);</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">sb</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="keyword" style="color:#569cd6;">new</span> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">StringBuilder</span><span class="punctuation">();</span><br/> <span class="keyword" style="color:#569cd6;">for</span> <span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="local name">i</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">i</span> <span class="operator" style="color:#b4b4b4;"><</span> <span class="identifier - local name - (TRANSIENT)">colLength</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">i</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="identifier - local name - (TRANSIENT)">sb</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">Append</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">"********"</span><span class="punctuation">);</span><br/> <span class="punctuation">}</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">sb</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">ToString</span><span class="punctuation">());</span><br/> <br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">$"方程: </span><span class="punctuation">{</span><span class="keyword" style="color:#569cd6;">string</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">Join</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">",\t"</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">resoveArr</span><span class="punctuation">)}</span><span class="string" style="color:#d69d85;"> = </span><span class="punctuation">{</span><span class="identifier - local name - (TRANSIENT)">backValue</span><span class="punctuation">}</span><span class="string" style="color:#d69d85;">"</span><span class="punctuation">);</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">$"結果: </span><span class="punctuation">{</span><span class="keyword" style="color:#569cd6;">string</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">Join</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">",\t"</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">resoveResultArr</span><span class="punctuation">)}</span><span class="string" style="color:#d69d85;">"</span><span class="punctuation">);</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">$"計算: </span><span class="punctuation">{</span><span class="keyword" style="color:#569cd6;">string</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">Join</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">",\t"</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">resoveResultArr</span><span class="operator" style="color:#b4b4b4;">.</span><span class="extension method name - identifier - (TRANSIENT)">Select</span><span class="punctuation">((</span><span class="parameter name">x</span><span class="punctuation">,</span> <span class="parameter name">index</span><span class="punctuation">)</span> <span class="operator" style="color:#b4b4b4;">=></span> <span class="string" style="color:#d69d85;">$"</span><span class="punctuation">{</span><span class="identifier - parameter name - (TRANSIENT)">x</span> <span class="operator" style="color:#b4b4b4;">*</span> <span class="identifier - local name - (TRANSIENT)">resoveArr</span><span class="punctuation">[</span><span class="identifier - parameter name - (TRANSIENT)">index</span><span class="punctuation">]}</span><span class="string" style="color:#d69d85;">"</span><span class="punctuation">))}</span><span class="string" style="color:#d69d85;">"</span><span class="punctuation">);</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">$"遞歸次數: </span><span class="punctuation">{</span><span class="identifier - local name - (TRANSIENT)">count</span><span class="punctuation">}</span><span class="string" style="color:#d69d85;">"</span><span class="punctuation">);</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">sb</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">ToString</span><span class="punctuation">());</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">();</span><br/><span class="preprocessor keyword" style="color:#9b9b9b;">#endif</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="operator" style="color:#b4b4b4;">!</span><span class="identifier - local name - (TRANSIENT)">flag</span><span class="punctuation">)</span><br/> <span class="keyword" style="color:#569cd6;">return</span> <span class="keyword" style="color:#569cd6;">null</span><span class="punctuation">;</span><br/> <br/> <span class="keyword" style="color:#569cd6;">for</span> <span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="local name">i</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">i</span> <span class="operator" style="color:#b4b4b4;"><</span> <span class="identifier - local name - (TRANSIENT)">resoveResultArr</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - property name - (TRANSIENT)">Length</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">i</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="identifier - local name - (TRANSIENT)">result</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">listColIndex</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">i</span><span class="punctuation">]]</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">resoveResultArr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">i</span><span class="punctuation">];</span><br/> <span class="punctuation">}</span><br/> <span class="punctuation">}</span><br/> <br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">listColIndex</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - property name - (TRANSIENT)">Count</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">backValue</span> <span class="operator" style="color:#b4b4b4;">%</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">backRowIndex</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">listColIndex</span><span class="punctuation">[</span><span class="number" style="color:#b5cea8;">0</span><span class="punctuation">]]</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="identifier - local name - (TRANSIENT)">result</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">listColIndex</span><span class="punctuation">[</span><span class="number" style="color:#b5cea8;">0</span><span class="punctuation">]]</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">backValue</span> <span class="operator" style="color:#b4b4b4;">/</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">backRowIndex</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">listColIndex</span><span class="punctuation">[</span><span class="number" style="color:#b5cea8;">0</span><span class="punctuation">]];</span><br/> <span class="punctuation">}</span><br/> <span class="keyword" style="color:#569cd6;">else</span><br/> <span class="punctuation">{</span><br/><span class="preprocessor keyword" style="color:#9b9b9b;">#if</span> <span class="identifier">DEBUG</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">number</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">backValue</span> <span class="operator" style="color:#b4b4b4;">*</span> <span class="number" style="color:#b5cea8;">1.0</span> <span class="operator" style="color:#b4b4b4;">/</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">backRowIndex</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">listColIndex</span><span class="punctuation">[</span><span class="number" style="color:#b5cea8;">0</span><span class="punctuation">]];</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">$"第</span><span class="punctuation">{</span><span class="identifier - local name - (TRANSIENT)">backRow</span><span class="punctuation">}</span><span class="string" style="color:#d69d85;">行 </span><span class="punctuation">{</span><span class="identifier - local name - (TRANSIENT)">backValue</span><span class="punctuation">}</span><span class="string" style="color:#d69d85;">/</span><span class="punctuation">{</span><span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">backRowIndex</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">listColIndex</span><span class="punctuation">[</span><span class="number" style="color:#b5cea8;">0</span><span class="punctuation">]]}</span><span class="string" style="color:#d69d85;"> = </span><span class="punctuation">{</span><span class="identifier - local name - (TRANSIENT)">number</span><span class="punctuation">}</span><span class="string" style="color:#d69d85;">, 不能被被整除計算失敗"</span><span class="punctuation">);</span><br/><span class="preprocessor keyword" style="color:#9b9b9b;">#endif</span><br/> <span class="keyword" style="color:#569cd6;">return</span> <span class="keyword" style="color:#569cd6;">null</span><span class="punctuation">;</span><br/> <span class="punctuation">}</span><br/> <span class="punctuation">}</span><br/> <br/> <br/> <br/> <span class="keyword" style="color:#569cd6;">for</span> <span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="local name">row</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">backRowIndex</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">row</span> <span class="operator" style="color:#b4b4b4;">>=</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">row</span><span class="operator" style="color:#b4b4b4;">--</span><span class="punctuation">)</span> <span class="comment" style="color:#57a64a;">//從倒數第二行開始往前迭代</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">)</span><br/> <span class="keyword" style="color:#569cd6;">continue</span><span class="punctuation">;</span><br/> <br/> <span class="keyword" style="color:#569cd6;">int</span> <span class="local name">addResult</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">;</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">currlist</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="keyword" style="color:#569cd6;">new</span> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">List</span><span class="punctuation"><</span><span class="keyword" style="color:#569cd6;">int</span><span class="punctuation">>();</span><br/> <span class="keyword" style="color:#569cd6;">for</span> <span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="local name">j</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">j</span> <span class="operator" style="color:#b4b4b4;"><</span> <span class="identifier - local name - (TRANSIENT)">colLength</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="number" style="color:#b5cea8;">2</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">j</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">)</span><span class="comment" style="color:#57a64a;">//j=2 j 最大值爲2,每行未知數可能不止一個,故須要遍歷已知的未知數並代入</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="operator" style="color:#b4b4b4;">!</span><span class="identifier - local name - (TRANSIENT)">result</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">j</span> <span class="operator" style="color:#b4b4b4;">+</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">]</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - property name - (TRANSIENT)">HasValue</span> <span class="operator" style="color:#b4b4b4;">&&</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">j</span> <span class="operator" style="color:#b4b4b4;">+</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">!=</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">)</span><br/> <span class="identifier - local name - (TRANSIENT)">currlist</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">Add</span><span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">j</span> <span class="operator" style="color:#b4b4b4;">+</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">);</span><span class="comment" style="color:#57a64a;">//把沒有計算出結果的列的索引存入</span><br/> <span class="keyword" style="color:#569cd6;">else</span><br/> <span class="identifier - local name - (TRANSIENT)">addResult</span> <span class="operator" style="color:#b4b4b4;">+=</span> <span class="identifier - local name - (TRANSIENT)">result</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">j</span> <span class="operator" style="color:#b4b4b4;">+</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">]</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">GetValueOrDefault</span><span class="punctuation">()</span> <span class="operator" style="color:#b4b4b4;">*</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">j</span> <span class="operator" style="color:#b4b4b4;">+</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">];</span><span class="comment" style="color:#57a64a;">//k表明計算的行,j+1表明的列,係數與解要對應,故都爲 j+1</span><br/> <span class="punctuation">}</span><br/> <br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">calculateValue</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">colLength</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="identifier - local name - (TRANSIENT)">addResult</span><span class="punctuation">;</span><br/> <br/> <span class="comment" style="color:#57a64a;">//發現沒有計算出結果的列 解不定方程</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">currlist</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - property name - (TRANSIENT)">Count</span> <span class="operator" style="color:#b4b4b4;">></span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="identifier - local name - (TRANSIENT)">currlist</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">Add</span><span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">);</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">resoveArr</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">currlist</span><span class="operator" style="color:#b4b4b4;">.</span><span class="extension method name - identifier - (TRANSIENT)">Select</span><span class="punctuation">(</span><span class="parameter name">x</span> <span class="operator" style="color:#b4b4b4;">=></span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">,</span> <span class="identifier - parameter name - (TRANSIENT)">x</span><span class="punctuation">])</span><span class="operator" style="color:#b4b4b4;">.</span><span class="extension method name - identifier - (TRANSIENT)">ToArray</span><span class="punctuation">();</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">resoveResultArr</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="keyword" style="color:#569cd6;">new</span> <span class="keyword" style="color:#569cd6;">int</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">currlist</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - property name - (TRANSIENT)">Count</span><span class="punctuation">];</span><br/> <br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">count</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">;</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">flag</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - method name - (TRANSIENT)">ResoveIndefiniteEquation</span><span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">resoveArr</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">calculateValue</span><span class="punctuation">,</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">,</span> <span class="keyword" style="color:#569cd6;">ref</span> <span class="identifier - local name - (TRANSIENT)">resoveResultArr</span><span class="punctuation">,</span> <span class="keyword" style="color:#569cd6;">ref</span> <span class="identifier - local name - (TRANSIENT)">count</span><span class="punctuation">);</span><br/><span class="preprocessor keyword" style="color:#9b9b9b;">#if</span> <span class="identifier">DEBUG</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">();</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">$"----發現第</span><span class="punctuation">{</span><span class="identifier - local name - (TRANSIENT)">row</span> <span class="operator" style="color:#b4b4b4;">+</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">}</span><span class="string" style="color:#d69d85;">行 第(</span><span class="punctuation">{</span><span class="keyword" style="color:#569cd6;">string</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">Join</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">","</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">currlist</span><span class="punctuation">)}</span><span class="string" style="color:#d69d85;">)列 沒有計算出結果,須要解不定方程"</span><span class="punctuation">);</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">sb</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="keyword" style="color:#569cd6;">new</span> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">StringBuilder</span><span class="punctuation">();</span><br/> <span class="keyword" style="color:#569cd6;">for</span> <span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="local name">i</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">i</span> <span class="operator" style="color:#b4b4b4;"><</span> <span class="identifier - local name - (TRANSIENT)">colLength</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">i</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="identifier - local name - (TRANSIENT)">sb</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">Append</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">"********"</span><span class="punctuation">);</span><br/> <span class="punctuation">}</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">sb</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">ToString</span><span class="punctuation">());</span><br/> <br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">$"方程: </span><span class="punctuation">{</span><span class="keyword" style="color:#569cd6;">string</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">Join</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">",\t"</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">resoveArr</span><span class="punctuation">)}</span><span class="string" style="color:#d69d85;"> = </span><span class="punctuation">{</span><span class="identifier - local name - (TRANSIENT)">calculateValue</span><span class="punctuation">}</span><span class="string" style="color:#d69d85;">"</span><span class="punctuation">);</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">$"結果: </span><span class="punctuation">{</span><span class="keyword" style="color:#569cd6;">string</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">Join</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">",\t"</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">resoveResultArr</span><span class="punctuation">)}</span><span class="string" style="color:#d69d85;">"</span><span class="punctuation">);</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">$"計算: </span><span class="punctuation">{</span><span class="keyword" style="color:#569cd6;">string</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">Join</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">",\t"</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">resoveResultArr</span><span class="operator" style="color:#b4b4b4;">.</span><span class="extension method name - identifier - (TRANSIENT)">Select</span><span class="punctuation">((</span><span class="parameter name">x</span><span class="punctuation">,</span> <span class="parameter name">index</span><span class="punctuation">)</span> <span class="operator" style="color:#b4b4b4;">=></span> <span class="string" style="color:#d69d85;">$"</span><span class="punctuation">{</span><span class="identifier - parameter name - (TRANSIENT)">x</span> <span class="operator" style="color:#b4b4b4;">*</span> <span class="identifier - local name - (TRANSIENT)">resoveArr</span><span class="punctuation">[</span><span class="identifier - parameter name - (TRANSIENT)">index</span><span class="punctuation">]}</span><span class="string" style="color:#d69d85;">"</span><span class="punctuation">))}</span><span class="string" style="color:#d69d85;">"</span><span class="punctuation">);</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">$"遞歸次數: </span><span class="punctuation">{</span><span class="identifier - local name - (TRANSIENT)">count</span><span class="punctuation">}</span><span class="string" style="color:#d69d85;">"</span><span class="punctuation">);</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">sb</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">ToString</span><span class="punctuation">());</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">();</span><br/><span class="preprocessor keyword" style="color:#9b9b9b;">#endif</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="operator" style="color:#b4b4b4;">!</span><span class="identifier - local name - (TRANSIENT)">flag</span><span class="punctuation">)</span><br/> <span class="keyword" style="color:#569cd6;">return</span> <span class="keyword" style="color:#569cd6;">null</span><span class="punctuation">;</span><br/> <br/> <span class="keyword" style="color:#569cd6;">for</span> <span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="local name">i</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">i</span> <span class="operator" style="color:#b4b4b4;"><</span> <span class="identifier - local name - (TRANSIENT)">resoveResultArr</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - property name - (TRANSIENT)">Length</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">i</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="identifier - local name - (TRANSIENT)">result</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">currlist</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">i</span><span class="punctuation">]]</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">resoveResultArr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">i</span><span class="punctuation">];</span><br/> <span class="punctuation">}</span><br/> <span class="punctuation">}</span><br/> <span class="keyword" style="color:#569cd6;">else</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">calculateValue</span> <span class="operator" style="color:#b4b4b4;">%</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="identifier - local name - (TRANSIENT)">result</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">calculateValue</span> <span class="operator" style="color:#b4b4b4;">/</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">];</span><span class="comment" style="color:#57a64a;">//本行的未知數用本行最右邊數-本行已知未知數代入係數之差 再除以本未知數係數</span><br/> <span class="punctuation">}</span><br/> <span class="keyword" style="color:#569cd6;">else</span><br/> <span class="punctuation">{</span><br/><span class="preprocessor keyword" style="color:#9b9b9b;">#if</span> <span class="identifier">DEBUG</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">number</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">calculateValue</span> <span class="operator" style="color:#b4b4b4;">*</span> <span class="number" style="color:#b5cea8;">1.0</span> <span class="operator" style="color:#b4b4b4;">/</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">];</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">$"第</span><span class="punctuation">{</span><span class="identifier - local name - (TRANSIENT)">row</span> <span class="operator" style="color:#b4b4b4;">+</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">}</span><span class="string" style="color:#d69d85;">行 </span><span class="punctuation">{</span><span class="identifier - local name - (TRANSIENT)">calculateValue</span><span class="punctuation">}</span><span class="string" style="color:#d69d85;">/</span><span class="punctuation">{</span><span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">row</span><span class="punctuation">]}</span><span class="string" style="color:#d69d85;"> = </span><span class="punctuation">{</span><span class="identifier - local name - (TRANSIENT)">number</span><span class="punctuation">}</span><span class="string" style="color:#d69d85;">, 不能被被整除計算失敗"</span><span class="punctuation">);</span><br/><span class="preprocessor keyword" style="color:#9b9b9b;">#endif</span><br/> <span class="keyword" style="color:#569cd6;">return</span> <span class="keyword" style="color:#569cd6;">null</span><span class="punctuation">;</span><br/> <span class="punctuation">}</span><br/> <span class="punctuation">}</span><br/> <span class="punctuation">}</span><br/> <br/><span class="preprocessor keyword" style="color:#9b9b9b;">#if</span> <span class="identifier">DEBUG</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">"----------結果------------"</span><span class="punctuation">);</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">Write</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">$"結果: </span><span class="punctuation">{</span><span class="keyword" style="color:#569cd6;">string</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">Join</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">","</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">result</span><span class="punctuation">)}</span><span class="string" style="color:#d69d85;">"</span><span class="punctuation">);</span><br/><span class="preprocessor keyword" style="color:#9b9b9b;">#endif</span><br/> <span class="keyword" style="color:#569cd6;">return</span> <span class="identifier - local name - (TRANSIENT)">result</span><span class="punctuation">;</span><br/> <span class="punctuation">}</span><br/> <br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> </span><span class="xml doc comment - delimiter" style="color:#608b4e;"><</span><span class="xml doc comment - name" style="color:#608b4e;">summary</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></span><br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> 解不定方程</span><br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> </span><span class="xml doc comment - delimiter" style="color:#608b4e;"></</span><span class="xml doc comment - name" style="color:#608b4e;">summary</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></span><br/> <span class="keyword" style="color:#569cd6;">public</span> <span class="keyword" style="color:#569cd6;">static</span> <span class="keyword" style="color:#569cd6;">bool</span> <span class="method name">ResoveIndefiniteEquation</span><span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span><span class="punctuation">[]</span> <span class="parameter name">arr</span><span class="punctuation">,</span> <span class="keyword" style="color:#569cd6;">int</span> <span class="parameter name">value</span><span class="punctuation">,</span> <span class="keyword" style="color:#569cd6;">int</span> <span class="parameter name">startIndex</span><span class="punctuation">,</span> <span class="keyword" style="color:#569cd6;">ref</span> <span class="keyword" style="color:#569cd6;">int</span><span class="punctuation">[]</span> <span class="parameter name">result</span><span class="punctuation">,</span> <span class="keyword" style="color:#569cd6;">ref</span> <span class="keyword" style="color:#569cd6;">int</span> <span class="parameter name">count</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="identifier - parameter name - (TRANSIENT)">count</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">;</span><span class="comment" style="color:#57a64a;">//遞歸計數,防止無限遞歸</span><br/> <br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">arr</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="keyword" style="color:#569cd6;">null</span> <span class="operator" style="color:#b4b4b4;">||</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - property name - (TRANSIENT)">Length</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">)</span><br/> <span class="keyword" style="color:#569cd6;">return</span> <span class="keyword" style="color:#569cd6;">false</span><span class="punctuation">;</span><br/> <br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - property name - (TRANSIENT)">Length</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">reValue</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - parameter name - (TRANSIENT)">value</span> <span class="operator" style="color:#b4b4b4;">/</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="number" style="color:#b5cea8;">0</span><span class="punctuation">];</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">value</span> <span class="operator" style="color:#b4b4b4;">%</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="number" style="color:#b5cea8;">0</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="number" style="color:#b5cea8;">0</span> <span class="operator" style="color:#b4b4b4;">&&</span> <span class="identifier - local name - (TRANSIENT)">reValue</span> <span class="operator" style="color:#b4b4b4;">>=</span> <span class="constant name - identifier - (TRANSIENT)">MinResove</span> <span class="operator" style="color:#b4b4b4;">&&</span> <span class="identifier - local name - (TRANSIENT)">reValue</span> <span class="operator" style="color:#b4b4b4;"><=</span> <span class="constant name - identifier - (TRANSIENT)">MaxResove</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="identifier - parameter name - (TRANSIENT)">result</span><span class="punctuation">[</span><span class="identifier - parameter name - (TRANSIENT)">startIndex</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">reValue</span><span class="punctuation">;</span><br/> <span class="keyword" style="color:#569cd6;">return</span> <span class="keyword" style="color:#569cd6;">true</span><span class="punctuation">;</span><br/> <span class="punctuation">}</span><br/> <span class="keyword" style="color:#569cd6;">return</span> <span class="keyword" style="color:#569cd6;">false</span><span class="punctuation">;</span><br/> <span class="punctuation">}</span><br/> <br/> <span class="comment" style="color:#57a64a;">//獲取第二部分元的最大公約數</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">commonDivisor</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="number" style="color:#b5cea8;">1</span><span class="punctuation">];</span><br/> <span class="keyword" style="color:#569cd6;">for</span> <span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="local name">i</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">i</span> <span class="operator" style="color:#b4b4b4;"><</span> <span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - property name - (TRANSIENT)">Length</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">);</span> <span class="identifier - local name - (TRANSIENT)">i</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="identifier - local name - (TRANSIENT)">commonDivisor</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - method name - (TRANSIENT)">GetCommonDivisor</span><span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">commonDivisor</span><span class="punctuation">,</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">i</span> <span class="operator" style="color:#b4b4b4;">+</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">]);</span><br/> <span class="punctuation">}</span><br/> <br/> <span class="keyword" style="color:#569cd6;">for</span> <span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="local name">i</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="constant name - identifier - (TRANSIENT)">MinResove</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">i</span> <span class="operator" style="color:#b4b4b4;"><=</span> <span class="constant name - identifier - (TRANSIENT)">MaxResove</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">i</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">currValue</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - parameter name - (TRANSIENT)">value</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="identifier - local name - (TRANSIENT)">i</span> <span class="operator" style="color:#b4b4b4;">*</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="number" style="color:#b5cea8;">0</span><span class="punctuation">];</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">currValue</span> <span class="operator" style="color:#b4b4b4;">%</span> <span class="identifier - local name - (TRANSIENT)">commonDivisor</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">newArr</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="keyword" style="color:#569cd6;">new</span> <span class="keyword" style="color:#569cd6;">int</span><span class="punctuation">[</span><span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - property name - (TRANSIENT)">Length</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">];</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Array</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">Copy</span><span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">,</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">newArr</span><span class="punctuation">,</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">,</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - property name - (TRANSIENT)">Length</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">);</span><br/> <br/> <span class="identifier - parameter name - (TRANSIENT)">result</span><span class="punctuation">[</span><span class="identifier - parameter name - (TRANSIENT)">startIndex</span><span class="punctuation">]</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">i</span><span class="punctuation">;</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">currArr</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - method name - (TRANSIENT)">ResoveIndefiniteEquation</span><span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">newArr</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">currValue</span><span class="punctuation">,</span> <span class="identifier - parameter name - (TRANSIENT)">startIndex</span> <span class="operator" style="color:#b4b4b4;">+</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">,</span> <span class="keyword" style="color:#569cd6;">ref</span> <span class="identifier - parameter name - (TRANSIENT)">result</span><span class="punctuation">,</span> <span class="keyword" style="color:#569cd6;">ref</span> <span class="identifier - parameter name - (TRANSIENT)">count</span><span class="punctuation">);</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">currArr</span><span class="punctuation">)</span><br/> <span class="keyword" style="color:#569cd6;">return</span> <span class="keyword" style="color:#569cd6;">true</span><span class="punctuation">;</span><br/> <br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">count</span> <span class="operator" style="color:#b4b4b4;">></span> <span class="number" style="color:#b5cea8;">1000000</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">"遞歸太深沒法求解"</span><span class="punctuation">);</span><br/> <span class="keyword" style="color:#569cd6;">return</span> <span class="keyword" style="color:#569cd6;">false</span><span class="punctuation">;</span><br/> <span class="punctuation">}</span><br/> <span class="punctuation">}</span><br/> <span class="punctuation">}</span><br/> <span class="keyword" style="color:#569cd6;">return</span> <span class="keyword" style="color:#569cd6;">false</span><span class="punctuation">;</span><br/> <span class="punctuation">}</span><br/> <br/> <span class="keyword" style="color:#569cd6;">private</span> <span class="keyword" style="color:#569cd6;">static</span> <span class="keyword" style="color:#569cd6;">void</span> <span class="method name">PrintArr</span><span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span><span class="punctuation">[,]</span> <span class="parameter name">arr</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">rowLength</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">GetLength</span><span class="punctuation">(</span><span class="number" style="color:#b5cea8;">0</span><span class="punctuation">);</span><span class="comment" style="color:#57a64a;">//行數</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">colLength</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">GetLength</span><span class="punctuation">(</span><span class="number" style="color:#b5cea8;">1</span><span class="punctuation">);</span><span class="comment" style="color:#57a64a;">//列數</span><br/> <br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">sb</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="keyword" style="color:#569cd6;">new</span> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">StringBuilder</span><span class="punctuation">();</span><br/> <span class="keyword" style="color:#569cd6;">for</span> <span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="local name">i</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">i</span> <span class="operator" style="color:#b4b4b4;"><</span> <span class="identifier - local name - (TRANSIENT)">colLength</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">i</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="identifier - local name - (TRANSIENT)">sb</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">Append</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">"--------"</span><span class="punctuation">);</span><br/> <span class="punctuation">}</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">sb</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">ToString</span><span class="punctuation">());</span><br/> <span class="keyword" style="color:#569cd6;">for</span> <span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="local name">i</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">i</span> <span class="operator" style="color:#b4b4b4;"><</span> <span class="identifier - local name - (TRANSIENT)">rowLength</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">i</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">for</span> <span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="local name">j</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">j</span> <span class="operator" style="color:#b4b4b4;"><</span> <span class="identifier - local name - (TRANSIENT)">colLength</span><span class="punctuation">;</span> <span class="identifier - local name - (TRANSIENT)">j</span><span class="operator" style="color:#b4b4b4;">++</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">Write</span><span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">arr</span><span class="punctuation">[</span><span class="identifier - local name - (TRANSIENT)">i</span><span class="punctuation">,</span> <span class="identifier - local name - (TRANSIENT)">j</span><span class="punctuation">]);</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">str</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">j</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">colLength</span> <span class="operator" style="color:#b4b4b4;">-</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">)</span> <span class="operator" style="color:#b4b4b4;">?</span> <span class="string" style="color:#d69d85;">""</span> <span class="operator" style="color:#b4b4b4;">:</span> <span class="string" style="color:#d69d85;">","</span><span class="punctuation">;</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">Write</span><span class="punctuation">(</span><span class="string" style="color:#d69d85;">$" </span><span class="punctuation">{</span><span class="identifier - local name - (TRANSIENT)">str</span><span class="punctuation">}</span><span class="string" style="color:#d69d85;">\t "</span><span class="punctuation">);</span><br/> <span class="punctuation">}</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">WriteLine</span><span class="punctuation">();</span><br/> <span class="punctuation">}</span><br/> <span class="punctuation">}</span><br/> <br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> </span><span class="xml doc comment - delimiter" style="color:#608b4e;"><</span><span class="xml doc comment - name" style="color:#608b4e;">summary</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></span><br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> 求最大公約數</span><br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> </span><span class="xml doc comment - delimiter" style="color:#608b4e;"></</span><span class="xml doc comment - name" style="color:#608b4e;">summary</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></span><br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> </span><span class="xml doc comment - delimiter" style="color:#608b4e;"><</span><span class="xml doc comment - name" style="color:#608b4e;">param</span><span class="xml doc comment - attribute name" style="color:#c8c8c8;"> name</span><span class="xml doc comment - delimiter" style="color:#608b4e;">=</span><span class="xml doc comment - attribute quotes" style="color:#c8c8c8;">"</span><span class="identifier - parameter name - (TRANSIENT)">a</span><span class="xml doc comment - attribute quotes" style="color:#c8c8c8;">"</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></</span><span class="xml doc comment - name" style="color:#608b4e;">param</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></span><br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> </span><span class="xml doc comment - delimiter" style="color:#608b4e;"><</span><span class="xml doc comment - name" style="color:#608b4e;">param</span><span class="xml doc comment - attribute name" style="color:#c8c8c8;"> name</span><span class="xml doc comment - delimiter" style="color:#608b4e;">=</span><span class="xml doc comment - attribute quotes" style="color:#c8c8c8;">"</span><span class="identifier - parameter name - (TRANSIENT)">b</span><span class="xml doc comment - attribute quotes" style="color:#c8c8c8;">"</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></</span><span class="xml doc comment - name" style="color:#608b4e;">param</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></span><br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> </span><span class="xml doc comment - delimiter" style="color:#608b4e;"><</span><span class="xml doc comment - name" style="color:#608b4e;">returns</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></</span><span class="xml doc comment - name" style="color:#608b4e;">returns</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></span><br/> <span class="keyword" style="color:#569cd6;">public</span> <span class="keyword" style="color:#569cd6;">static</span> <span class="keyword" style="color:#569cd6;">int</span> <span class="method name">GetCommonDivisor</span><span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="parameter name">a</span><span class="punctuation">,</span> <span class="keyword" style="color:#569cd6;">int</span> <span class="parameter name">b</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">a</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="number" style="color:#b5cea8;">0</span> <span class="operator" style="color:#b4b4b4;">||</span> <span class="identifier - parameter name - (TRANSIENT)">b</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">)</span> <span class="keyword" style="color:#569cd6;">return</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">;</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Math</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">Abs</span><span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">a</span><span class="punctuation">)</span> <span class="operator" style="color:#b4b4b4;"><</span> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Math</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">Abs</span><span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">b</span><span class="punctuation">))</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">temp</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - parameter name - (TRANSIENT)">a</span><span class="punctuation">;</span><br/> <span class="identifier - parameter name - (TRANSIENT)">a</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - parameter name - (TRANSIENT)">b</span><span class="punctuation">;</span><br/> <span class="identifier - parameter name - (TRANSIENT)">b</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - local name - (TRANSIENT)">temp</span><span class="punctuation">;</span><br/> <span class="punctuation">}</span><br/> <span class="keyword" style="color:#569cd6;">return</span> <span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">a</span> <span class="operator" style="color:#b4b4b4;">%</span> <span class="identifier - parameter name - (TRANSIENT)">b</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">)</span> <span class="operator" style="color:#b4b4b4;">?</span> <span class="identifier - parameter name - (TRANSIENT)">b</span> <span class="operator" style="color:#b4b4b4;">:</span> <span class="identifier - method name - (TRANSIENT)">GetCommonDivisor</span><span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">a</span> <span class="operator" style="color:#b4b4b4;">%</span> <span class="identifier - parameter name - (TRANSIENT)">b</span><span class="punctuation">,</span> <span class="identifier - parameter name - (TRANSIENT)">b</span><span class="punctuation">);</span><br/> <span class="punctuation">}</span><br/> <br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> </span><span class="xml doc comment - delimiter" style="color:#608b4e;"><</span><span class="xml doc comment - name" style="color:#608b4e;">summary</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></span><br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> 求最小公倍數 </span><br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> </span><span class="xml doc comment - delimiter" style="color:#608b4e;"></</span><span class="xml doc comment - name" style="color:#608b4e;">summary</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></span><br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> </span><span class="xml doc comment - delimiter" style="color:#608b4e;"><</span><span class="xml doc comment - name" style="color:#608b4e;">param</span><span class="xml doc comment - attribute name" style="color:#c8c8c8;"> name</span><span class="xml doc comment - delimiter" style="color:#608b4e;">=</span><span class="xml doc comment - attribute quotes" style="color:#c8c8c8;">"</span><span class="identifier - parameter name - (TRANSIENT)">a</span><span class="xml doc comment - attribute quotes" style="color:#c8c8c8;">"</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></</span><span class="xml doc comment - name" style="color:#608b4e;">param</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></span><br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> </span><span class="xml doc comment - delimiter" style="color:#608b4e;"><</span><span class="xml doc comment - name" style="color:#608b4e;">param</span><span class="xml doc comment - attribute name" style="color:#c8c8c8;"> name</span><span class="xml doc comment - delimiter" style="color:#608b4e;">=</span><span class="xml doc comment - attribute quotes" style="color:#c8c8c8;">"</span><span class="identifier - parameter name - (TRANSIENT)">b</span><span class="xml doc comment - attribute quotes" style="color:#c8c8c8;">"</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></</span><span class="xml doc comment - name" style="color:#608b4e;">param</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></span><br/> <span class="xml doc comment - delimiter" style="color:#608b4e;">///</span><span class="xml doc comment - text" style="color:#608b4e;"> </span><span class="xml doc comment - delimiter" style="color:#608b4e;"><</span><span class="xml doc comment - name" style="color:#608b4e;">returns</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></</span><span class="xml doc comment - name" style="color:#608b4e;">returns</span><span class="xml doc comment - delimiter" style="color:#608b4e;">></span><br/> <span class="keyword" style="color:#569cd6;">public</span> <span class="keyword" style="color:#569cd6;">static</span> <span class="keyword" style="color:#569cd6;">int</span> <span class="method name">GetMinCommonMultiple</span><span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">int</span> <span class="parameter name">a</span><span class="punctuation">,</span> <span class="keyword" style="color:#569cd6;">int</span> <span class="parameter name">b</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">commonDivisor</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="identifier - method name - (TRANSIENT)">GetCommonDivisor</span><span class="punctuation">(</span><span class="identifier - parameter name - (TRANSIENT)">a</span><span class="punctuation">,</span> <span class="identifier - parameter name - (TRANSIENT)">b</span><span class="punctuation">);</span><br/> <span class="keyword" style="color:#569cd6;">if</span> <span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">commonDivisor</span> <span class="operator" style="color:#b4b4b4;">==</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">)</span><br/> <span class="keyword" style="color:#569cd6;">return</span> <span class="number" style="color:#b5cea8;">0</span><span class="punctuation">;</span><br/> <span class="keyword" style="color:#569cd6;">return</span> <span class="identifier - parameter name - (TRANSIENT)">a</span> <span class="operator" style="color:#b4b4b4;">*</span> <span class="identifier - parameter name - (TRANSIENT)">b</span> <span class="operator" style="color:#b4b4b4;">/</span> <span class="identifier - local name - (TRANSIENT)">commonDivisor</span><span class="punctuation">;</span><br/> <span class="punctuation">}</span><br/> <span class="punctuation">}</span></div>ui
<div style="font-family: Arial; font-size: 13; color: gainsboro; background: #1e1e1e;"> <span class="keyword" style="color:#569cd6;">static</span> <span class="keyword" style="color:#569cd6;">void</span> <span class="method name">Main</span><span class="punctuation">(</span><span class="keyword" style="color:#569cd6;">string</span><span class="punctuation">[]</span> <span class="parameter name">args</span><span class="punctuation">)</span><br/> <span class="punctuation">{</span><br/> <span class="keyword" style="color:#569cd6;">var</span> <span class="local name">arr</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="keyword" style="color:#569cd6;">new</span> <span class="keyword" style="color:#569cd6;">int</span><span class="punctuation">[,]</span><br/> <span class="punctuation">{</span><br/> <span class="punctuation">{</span> <span class="number" style="color:#b5cea8;">2</span><span class="punctuation">,</span> <span class="number" style="color:#b5cea8;">3</span><span class="punctuation">,</span> <span class="number" style="color:#b5cea8;">4</span><span class="punctuation">,</span> <span class="number" style="color:#b5cea8;">3</span><span class="punctuation">,</span> <span class="number" style="color:#b5cea8;">21</span> <span class="punctuation">},</span><br/> <span class="punctuation">{</span> <span class="number" style="color:#b5cea8;">3</span><span class="punctuation">,</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">,</span> <span class="number" style="color:#b5cea8;">6</span><span class="punctuation">,</span> <span class="number" style="color:#b5cea8;">2</span><span class="punctuation">,</span> <span class="number" style="color:#b5cea8;">17</span> <span class="punctuation">},</span><br/> <span class="punctuation">{</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">,</span> <span class="number" style="color:#b5cea8;">3</span><span class="punctuation">,</span> <span class="number" style="color:#b5cea8;">2</span><span class="punctuation">,</span> <span class="number" style="color:#b5cea8;">1</span><span class="punctuation">,</span> <span class="number" style="color:#b5cea8;">12</span><span class="punctuation">},</span><br/> <span class="punctuation">};</span><br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">GaussHelper</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">ResoveGauss</span><span class="punctuation">(</span><span class="identifier - local name - (TRANSIENT)">arr</span><span class="punctuation">);</span><br/> <br/> <span class="class name - identifier - (TRANSIENT)" style="color:#4ec9b0;">Console</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier - method name - (TRANSIENT)">ReadKey</span><span class="punctuation">();</span><br/> <span class="punctuation">}</span></div>spa
原文出處:https://www.cnblogs.com/castyuan/p/10251885.htmlxml