Skip to content

Instantly share code, notes, and snippets.

@Dinner1111
Last active August 29, 2015 14:09
Show Gist options
  • Save Dinner1111/f9d36967241438c3cf76 to your computer and use it in GitHub Desktop.
Save Dinner1111/f9d36967241438c3cf76 to your computer and use it in GitHub Desktop.
using System;
namespace ProjectEuler
{
class Problem_10
{
/*
* The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
*
* Find the sum of all the primes below two million.
*/
public static void Run()
{
int number = 2000000;
long sum = 2;
for (int divisor = 3; divisor < number; divisor += 2)
{
bool isPrime = true;
for (int index = 3; index < Math.Sqrt(divisor); index += 2)
if (divisor % index == 0)
{
isPrime = false;
break;
}
if (isPrime)
sum += divisor;
}
Console.WriteLine(sum);
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment