fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5. bool isPrime(int n);
  6.  
  7. int main()
  8. {
  9.  
  10. int num;
  11. cin >> num;
  12. int x1, x2;
  13.  
  14. while(num)
  15. {
  16. cin >> x1 >> x2;
  17. while(x1 <= x2)
  18. {
  19. if(isPrime(x1))
  20. cout << x1 << endl;
  21. x1++;
  22. }
  23. num--;
  24. }
  25. return 0;
  26. }
  27.  
  28.  
  29. bool isPrime(int n)
  30. {
  31. if(n == 1 || n == 0)
  32. return false;
  33.  
  34. if(n % 2 == 0 && n != 2)
  35. return false;
  36.  
  37. int sq = sqrt(n);
  38.  
  39. for(int i = 3;i <= sq; )
  40. {
  41. if(n % i == 0)
  42. {
  43. return false;
  44. }
  45. i += 2;
  46. }
  47.  
  48. return true;
  49. }
Success #stdin #stdout 0s 2856KB
stdin
2
1 10
3 5
stdout
2
3
5
7
3
5