Created
April 29, 2020 21:26
-
-
Save gavinsykes/3ee34839b0e60c2e36efde39e926eae1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 gen_max_prime($n) { | |
if (($n < 1) || !is_int($n)) { | |
return undefined; | |
} | |
while(!($n&1)) { | |
$result = 2; | |
$n >> 1; | |
} | |
for ($i = 3;sqrt($n) + 1,$i += 2) { | |
while ($n%$i == 0) { | |
$result = $i; | |
$n = $n / $i; | |
} | |
} | |
if ($n > 2) { | |
$result = $n; | |
} | |
return $result; | |
} | |
$v = $_REQUEST['val']; | |
echo gen_max_prime($v); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment