fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. bool prime (int n){
  5. if(n==1)
  6. return false;
  7. else if(n==2)
  8. return true;
  9. else if(n%2==0)
  10. return false;
  11. else{
  12. for(int i=3;i<=sqrt(n);i+=2){
  13. if(n%i==0)
  14. return false;
  15. }
  16. }
  17. return true;
  18. }
  19. int main() {
  20. int t, i, a,b;
  21. cin>>t;
  22. while(t--){
  23. cin>>a>>b;
  24. for(i=a;i<=b;i++){
  25. if(prime(i))
  26. cout<<i<<endl;
  27. }
  28. cout<<endl;
  29. }
  30. return 0;
  31. }
Success #stdin #stdout 0s 4504KB
stdin
2
1 10
3 5
stdout
2
3
5
7

3
5