function primeMultiples($int) { $largestPrime = 0; $primes = getPrimes(10000); foreach ($primes as $prime) { $check = $int % $prime; if ($check == 0 && $prime > $largestPrime) { $largestPrime = $prime; } } return $largestPrime; }
$check = __primeCheck($primes, $int); if ($check == TRUE) { $primes[] = $int; $length++; } $int++; break; } } return $primes; } /** * * Checks if a number is a prime or not. * @param int $num */ function __primeCheck($primes, $num) { if ($num == 2) { return TRUE; } foreach ($primes as $prime) { $primeCheck = $num % $prime; if ($primeCheck == 0) { return FALSE; } } return TRUE; } $primes = getPrimes(10001); print $primes[10000];
if ($primeCheck == 0) { return FALSE; } } return TRUE; } function highestMultiplePrimes($primes, $max) { foreach ($primes as $prime) { $int = $prime; while ($int + $prime <= $max) { $int = $int + $prime; } $numbers[] = $int; } $numbers = array_unique($numbers); return $numbers; } function multiply($numbers) { $result = 1; foreach ($numbers as $number) { $result = $result * $number; } return $result; } $max = 20; $primes = getPrimes($max); $numbers = highestMultiplePrimes($primes, $max); $result = multiply($numbers); print "{$result}";
} } function tPrime($n) { $len = strlen($n); for ($i = 2; $i <= $len; $i++) { if (isPrime(substr($n, 0, $i)) && isPrime(substr($n, strlen($n) - $i, $i))) { } else { return false; } } return true; } $n = 23; $tPrimes = array(); getPrimes(50); while (count($tPrimes) < 11) { if (tPrime($n)) { if (isPrime($n)) { $tPrimes[] = $n; echo "."; } } $n++; while (!in_array(substr($n, 0, 1), array(2, 3, 5, 7)) || !in_array(substr($n, strlen($n) - 1, 1), array(2, 3, 5, 7))) { $n++; } } echo "\n"; $total = array_sum($tPrimes); result(748317, $total);