Guest User

Untitled

a guest
Jun 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <string>
  6. #include <vector>
  7.  
  8. using namespace std;
  9.  
  10. const int MAX = 34000;
  11.  
  12. int polje[MAX + 1];
  13. vector <int> prosti;
  14.  
  15. void eratosten () {
  16.     for (int i = 2; i <= (int) sqrt (MAX); i++) {
  17.         if (polje[i] == 0) {
  18.             prosti.push_back (i);
  19.             for (int j = i * 2; j <= MAX; j += i) {
  20.                 polje[j] = 1;  
  21.             }  
  22.         }
  23.     }  
  24. }
  25.  
  26. int prost (int broj) {
  27.     if (broj == 1) {
  28.         return 0;  
  29.     }
  30.     int gg = (int) sqrt (broj);
  31.     for (int i = 0; prosti[i] <= gg; i++) {
  32.         if (broj % prosti[i] == 0) {
  33.             return 0;
  34.         }
  35.     }  
  36.     return 1;
  37. }
  38.  
  39. int main() {
  40.     eratosten ();
  41.     int t;
  42.     scanf ("%d", &t);
  43.     for (int i = 0; i < t; i++) {
  44.         int a, b;
  45.         scanf ("%d %d", &a, &b);
  46.         for (int j = a; j <= b; j++) {
  47.             if (prost (j)) {
  48.                 printf ("%d\n", j);  
  49.             }
  50.         }  
  51.         printf ("\n");
  52.     }
  53.     //system ("PAUSE");
  54.     return 0;
  55. }
Add Comment
Please, Sign In to add comment