我使用以下來找出共同的因數。如何在PHP中查找兩個數字的公約數?
但是在某些情況下不滿足除數計數。
我的代碼:
$x = 66928;
$y = 66992;
$c_a = [];
$c_b = [];
$d = 1;
while ($d_a <= $x) {
if (is_int($x/$d)) $c_a[] = $d;
$d++;
}
$d = 1;
while ($d_b <= $y) {
if (is_int($y/$d)) $c_b[] = $d;
$d++;
}
echo count($c_a);
echo count($c_b);
// Output
$c_a = 20;
$c_b = 20;
因爲,在某些情況下,它不會工作。
這種計算方式是正確的嗎? 還是有什麼建議?
你想計算兩個公因子的數量? –
是的......此代碼不適用於大數字.. –
有關大數字在php [更多信息](http://stackoverflow.com/questions/211345/working-with-large-numbers-in-php) – Ken