Last active
December 6, 2018 12:50
-
-
Save bagart/83f6e72f5f4ca67dd60be6c4fb0d515a to your computer and use it in GitHub Desktop.
big number has a has_factor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function chk_simple(int $value): bool { | |
$square_root_of_value = sqrt($value); | |
if (!($value % 2) ||!($value % 3) || $square_root_of_value === ceil($square_root_of_value)) { | |
return false; | |
} | |
$square_root_of_value = (int)$square_root_of_value; | |
$del3 = 0; | |
$iterations = 0; | |
for ($i = 5;$i < $square_root_of_value; $i = $i + 2) { | |
++$iterations; | |
if (++$del3 > 2) { | |
$del3 = 0; | |
//var_dump('skip:'. $del3 . '-'.$i); | |
continue; | |
} | |
if (!($value % $i)) { | |
var_dump([ | |
'num' => $i, | |
'iterations' => $iterations | |
]); | |
return false; | |
} | |
} | |
var_dump([ | |
'num' => false, | |
'iterations' => $iterations | |
]); | |
return true; | |
} | |
var_dump(chk_simple(126221)); | |
var_dump(chk_simple(600851475143)); | |
var_dump(chk_simple(2147483647)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment