SHARE
TWEET

Numeros primos hasta 500

a guest Oct 16th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<vector>
  3.  
  4. using namespace std;
  5.  
  6. #define MAX 10000
  7.  
  8. vector<bool> criba(MAX, true);
  9.  
  10. void initCriba() {
  11.     criba[0] = false;
  12.     criba[1] = false;
  13.     for (int i = 0;i < MAX;i++) {
  14.         if (criba[i]) {
  15.             for (int p = i * 2;p < MAX;p += i) { //P recorre todos los multiplos de i
  16.                 criba[p] = false;
  17.             }
  18.         }
  19.     }
  20. }
  21.  
  22. bool isPrime(int n) {
  23.     return criba[n];
  24. }
  25.  
  26. int main() {
  27.     initCriba();
  28.  
  29.     for (int i = 0;i < 500;++i) {
  30.         if (isPrime(i)) {
  31.             cout << i << " ";
  32.         }
  33.     }
  34.     system("pause");
  35.     return 0;
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top