1 means there is common factor, so has appeared earlier in list. // Also, limit output to denominators with small error. if ((gcd($denom, $intNumer) == 1) and (abs($error) < $largestError)) printf("%3d %3d %+1.6f\r\n", $denom, $intNumer, $error); } // http://stackoverflow.com/questions/13828011/look-for-the-gcd-greatest-common-divisor-of-more-than-2-integers function gcd($a, $b) { return $b ? gcd($b, $a % $b) : $a; } ?>