Project Euler - Problem 10
Posted on Tue, 20/12/2011 - 15:26
Question
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
Solution
$sum = 2;
for ($i = 2; $i < 2000000; $i++) {
if ($i % 2 != 1) {
continue;
}
$d = 3;
$x = sqrt($i);
while (($i % $d != 0) && $d < $x) {
$d += 2;
}
if ((($i % $d == 0 && $i != $d) * 1) == 0) {
$sum += $i;
}
}
echo $sum;Time taken to execute: 30.5757 second.
Project Euler - Problem 4
Posted on Wed, 14/12/2011 - 14:20
Question
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the product of two 3-digit numbers.
Project Euler - Problem 3
Posted on Wed, 14/12/2011 - 14:09
Question
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?