Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static void Problem10()
- {
- long sum = 0;
- for (int i = 2; i < 2000000; i++)
- {
- if (Helpers.IsPrime(i))
- {
- sum += i;
- }
- }
- Console.WriteLine(sum);
- }
- public static class Helpers
- {
- public static bool IsPrime(int candidate)
- {
- if (candidate == 1) return false;
- // Check even.
- if ((candidate & 1) == 0)
- {
- return candidate == 2;
- }
- for (int i = 3; i*i <= candidate; i+=2)
- {
- if (candidate % i == 0)
- {
- return false;
- }
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement