fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int numberOfLines;
  7. int m; //beginning of prime numbers
  8. int n; //ending of prime numbers
  9. int x;
  10. int *arrayPtr;
  11. //Read in the numbers
  12. std::cin >> numberOfLines;
  13.  
  14. //Create an array with numberOfLines
  15. for (int i = 0; i < numberOfLines; i++){
  16. std::cin >> m >> n;
  17. arrayPtr = new int[(n-m)+1];
  18. int counter = 0;
  19.  
  20. //Check condition m >= 1 && n >=1
  21. if (m >= 1 && n >= 1)
  22.  
  23. //check second condition
  24. if ( m <= 1000000000 && n <= 1000000000)
  25. //check third condition
  26. if (n-m<= 100000){
  27. for (int x = m; x <= n; x++){
  28. if (x == 1){
  29. }
  30. else if (x == 2 || x == 3 || x == 5 || x == 7 || x == 11){
  31. arrayPtr[counter] = x;
  32. counter++;
  33. }
  34. else if (x%2 == 0 || x%3 == 0 || x%5 == 0 || x%7 == 0 || x%11 == 0)
  35. {}
  36. else
  37. {
  38. arrayPtr[counter] = x;
  39. counter++;
  40. }
  41. }
  42. }
  43.  
  44. for (int i = 0; i < counter; i++)
  45. std::cout << arrayPtr[i] << "\n";
  46. std::cout << "\n";
  47. delete arrayPtr;
  48. }
  49.  
  50. return 0;
  51. }
Success #stdin #stdout 0s 3464KB
stdin
2
1 10
5 200
stdout
2
3
5
7

5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
101
103
107
109
113
127
131
137
139
149
151
157
163
167
169
173
179
181
191
193
197
199