Skip to content

Instantly share code, notes, and snippets.

@trys
Created April 8, 2015 16:02
Show Gist options
  • Save trys/237dadde0dcf0f81f458 to your computer and use it in GitHub Desktop.
Save trys/237dadde0dcf0f81f458 to your computer and use it in GitHub Desktop.
Problem Three
$factors = array();
$t = 600851475143;
for ( $d = 3; $d < 8462696833; $d++ ) {
$calc = $t / $d;
if ( in_array( $calc, $factors ) ) {
break;
}
if ( is_int( $calc ) ) {
$factors[] = $d;
$factors[] = $calc;
}
}
rsort( $factors );
$prime_factors = array();
$is_prime = true;
foreach ( $factors as $factor ) {
$is_prime = true;
for ( $d = 2; $d < $factor; $d++ ) {
if ( $factor % $d == 0 ) {
$is_prime = false;
break;
}
}
if ( $is_prime ) {
echo $factor;
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment