mituri

[C++] suma liczb pierwszych

Oct 1st, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. /*
  2. Project Euler("https://projecteuler.net/archives")
  3. Problem 10
  4.  
  5. The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
  6. Find the sum of all the primes below two million.
  7. */
  8.  
  9. int main(){
  10. long long sum = 0;
  11. int size = 2000000;
  12. bool prime = true;
  13. for(int i = 2; i < size; i++){
  14. for(int j = 2; j < i; j++){
  15. if( i%j == 0){
  16. prime = false;
  17. break;
  18. }
  19. }
  20. if(prime == true){
  21. sum += i;
  22. }
  23. if(prime == true) cout << i << " " << sum << endl;;
  24. prime = true;
  25. }
  26. system("PAUSE");
  27. }
Advertisement
Add Comment
Please, Sign In to add comment