Skip to content

Instantly share code, notes, and snippets.

@gavinsykes
Created April 29, 2020 21:26
Show Gist options
  • Save gavinsykes/3ee34839b0e60c2e36efde39e926eae1 to your computer and use it in GitHub Desktop.
Save gavinsykes/3ee34839b0e60c2e36efde39e926eae1 to your computer and use it in GitHub Desktop.
<?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