fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef vector<int> vi;
  5. typedef priority_queue<int> maxHeap;
  6. typedef priority_queue<int, vector<int>, greater<int>> minHeap;
  7. #define inputArray(a, n) \
  8.   for (int i = 0; i < n; i++) cin >> a[i];
  9. #define printArray(a, n) \
  10.   for (int i = 0; i < n; i++) cout << a[i] << endl;
  11. typedef pair<int, int> pii;
  12. #define endl "\n"
  13. #define PB push_back
  14. #define MP make_pair
  15. #define FF first
  16. #define SS second
  17. #define int long long
  18. #define MOD 1000000007
  19. #define PI 3.1415926535897932384626433832795
  20. #define clr(val, val1) memset(val, val1, sizeof(val))
  21. #define what_is(x) cerr << #x << " is " << x << endl;
  22. #define OnlineJudge \
  23.   freopen("input.txt", "r", stdin); \
  24.   freopen("output.txt", "w", stdout);
  25. #define FastIO \
  26.   ios_base::sync_with_stdio(false); \
  27.   cin.tie(NULL); \
  28.   cout.tie(NULL);
  29.  
  30. void additionals() {
  31. FastIO;
  32. OnlineJudge;
  33. }
  34. const int n = 100001;
  35. bitset<n> x;
  36. vector<int> primes;
  37.  
  38. void seive() {
  39. x.set();
  40. x[0] = x[1] = 0;
  41. // primes.clear();
  42. for (int i = 2; i * i <= n; i++) {
  43. if (x[i]) {
  44. int k = i * i;
  45. while (k <= n) {
  46. x[k] = 0;
  47. k += i;
  48. }
  49. }
  50. }
  51.  
  52. for (int i = 0; i <= n; i++) {
  53. if (x[i]) primes.PB(i);
  54. }
  55. }
  56. int32_t main() {
  57. additionals();
  58. int a, b;
  59. cin >> a >> b;
  60. seive();
  61. int segment[b - a + 1];
  62.  
  63. memset(segment, 1, sizeof(segment));
  64.  
  65. for (auto i : primes) {
  66. if (i * i > b) break;
  67.  
  68. int start = (a / i) * i;
  69. if (i >= a and i <= b) {
  70. start = i * 2;
  71. }
  72.  
  73. for (int j = start; j <= n; j += i) {
  74. segment[j - a] = 0;
  75. }
  76. }
  77. cout << "Result:" << endl;
  78. for (int i = a; i <= b; i++) {
  79. if (segment[i - a]) cout << i << " ";
  80. }
  81. cout << endl;
  82.  
  83. // for (auto i : primes) {
  84. // cout << i << " ";
  85. // }
  86.  
  87. return 0;
  88. }
Runtime error #stdin #stdout 0s 4204KB
stdin
10 1000
stdout
Standard output is empty