Last active
August 29, 2015 14:09
-
-
Save Dinner1111/f9d36967241438c3cf76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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