Category Archives: Project Euler

Solution to Problem 10 on Project Euler

Not the most challenging one, but still: The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. My Solution #include <stdio.h> #include <math.h> int isPrime(num){   int i;   if (num==2)     return 1;   for (i=2;i<sqrt(num)+1;i++){     if (num%i==0)       return 0;     } […]

Solution to Project Euler 8

In Problem 8 you need to find the greatest product of five consecutive digits of a 1000-digit number that is given. To find the solution I simply read the number into an array and then traversed it comparing the product of five digits at a time. #include <stdio.h> int main(){   int vet[1000];   int z,max,c,j,i=0;   while(i<1000){ […]

Solution to Project Euler 7

Here’s the description of the Problem 7: By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10 001st prime number? In order to find the solution I wrote a simple function to test whether a number n is […]

Solution to Project Euler 6

Problem 6 has the following description: The sum of the squares of the first ten natural numbers is, 12 + 22 + … + 102 = 385 The square of the sum of the first ten natural numbers is, (1 + 2 + … + 10)2 = 552 = 3025 Hence the difference between the […]

Solution to Project Euler 5

Problem 5 was relatively easier than the ones we saw so far. Here’s the description: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? […]

Solution to Project Euler 4

Here’s the description for Problem 4 on Project Euler: 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. As usual the brute force approach was my first guess, […]

Solution to Project Euler 3

Problem 3 on Project Euler is another easy one. Here’s the description: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? A simple brute force approach, testing all factors of the number to see if they are prime and storing the largest […]