MeehoweCK

Untitled

Nov 23rd, 2020
439
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool pierwsza(unsigned x)
  5. {
  6.     for(int i = 2; i * i <= x; ++i)
  7.         if(x % i == 0)
  8.             return false;
  9.     return true;
  10. }
  11.  
  12. unsigned ile_pierwszych(unsigned a, unsigned b)
  13. {
  14.     unsigned wynik = 0;
  15.     for(unsigned i = a; i <= b; ++i)
  16.         if(pierwsza(i))
  17.             ++wynik;
  18.     return wynik;
  19. }
  20.  
  21. int main()
  22. {
  23.     short n;
  24.     cin >> n;
  25.     unsigned tablica[2 * n];
  26.     for(unsigned short i = 0; i < 2 * n; ++i)
  27.         cin >> tablica[i];
  28.  
  29.     for(unsigned short i = 0; i < 2 * n; ++i)
  30.     {
  31.         cout << ile_pierwszych(tablica[i], tablica[i + 1]) << endl;
  32.         ++i;
  33.     }
  34. }
RAW Paste Data