Skip to content

Instantly share code, notes, and snippets.

@montyanderson
Created September 22, 2014 09:12
Show Gist options
  • Save montyanderson/299afbfd0288ef08fa8b to your computer and use it in GitHub Desktop.
Save montyanderson/299afbfd0288ef08fa8b to your computer and use it in GitHub Desktop.
<?php
$primes = array();
$input = 600851475143;
/* Find the primes */
for($i = 1; $i < 10000; $i++) {
$prime = gmp_strval(gmp_nextprime($i));
if(end($primes) != $prime) {
$primes[] = $prime;
}
}
/* Find largest factor */
foreach($primes as $prime) {
if($input % $prime == 0) {
$output = $prime;
}
}
echo $output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment