Created
September 22, 2014 09:12
-
-
Save montyanderson/299afbfd0288ef08fa8b to your computer and use it in GitHub Desktop.
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 | |
$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