fork(1) download
  1. #include<iostream>
  2. #include<math.h>
  3. #include<stdlib.h>
  4.  
  5. bool isPrime(int);
  6. using namespace std;
  7. int main()
  8. {
  9. int num_of_input, *from= NULL, *to=NULL;
  10. std::cin >> num_of_input;
  11. if (!num_of_input)
  12. return 0;
  13. from = (int*)malloc(sizeof(int));
  14. to = (int*)malloc(sizeof(int));
  15. if( !from || !to )
  16. return 0;
  17. int i=0, j=0;
  18. for(i=0; i<num_of_input; i++)
  19. {
  20. std::cin >> from[i];
  21. std::cin >> to[i];
  22. }
  23.  
  24. for(i=0;i< num_of_input; i++)
  25. {
  26. for(j=from[i]; j<=to[i]; j++)
  27. {
  28. if(j==1 || j==0)
  29. continue;
  30. else if(isPrime(j))
  31. std::cout << j << " ";
  32. }
  33. std::cout << endl;
  34. }
  35.  
  36. free(from);
  37. free(to);
  38. return 0;
  39. }
  40.  
  41. bool isPrime(int n)
  42. {
  43. for (int i=2; i<=int(sqrt(n)); i++)
  44. {
  45. if (n%i == 0)
  46. return 0;
  47. }
  48. return 1;
  49. }
  50.  
Success #stdin #stdout 0s 3476KB
stdin
2
1 10
3 5
stdout
2 3 5 7 
3 5