Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. private static void Problem10()
  2. {
  3. long sum = 0;
  4. for (int i = 2; i < 2000000; i++)
  5. {
  6. if (Helpers.IsPrime(i))
  7. {
  8. sum += i;
  9. }
  10. }
  11.  
  12. Console.WriteLine(sum);
  13. }
  14.  
  15. public static class Helpers
  16. {
  17. public static bool IsPrime(int candidate)
  18. {
  19. if (candidate == 1) return false;
  20. // Check even.
  21. if ((candidate & 1) == 0)
  22. {
  23. return candidate == 2;
  24. }
  25.  
  26. for (int i = 3; i*i <= candidate; i+=2)
  27. {
  28. if (candidate % i == 0)
  29. {
  30. return false;
  31. }
  32. }
  33.  
  34. return true;
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement