fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. long long l, r;
  4. bool snt[1000005], a[1000005];
  5.  
  6. main() {
  7. ios_base::sync_with_stdio(false);
  8. cin.tie(0); cout.tie(0);
  9. cin >> l >> r;
  10. int n = 1e6;
  11. for (int i = 2; i <= n; i++) snt[i] = true;
  12. for (int i = 1; i <= r - l + 1; i++) a[i] = true;
  13. for (int i = 2; i * i <= n; i++) {
  14. if (snt[i]) {
  15. for (int j = i * i; j <= n; j += i)
  16. snt[j] = false;
  17. }
  18. }
  19.  
  20. long long _n = sqrt(r);
  21. for (int i = 2; i <= _n; i++) {
  22. if (snt[i]) {
  23. long long k = l;
  24. if (l % i != 0) {
  25. k /= i;
  26. k++;
  27. k *= i;
  28. }
  29. k = max(k, 2LL * i);
  30. for (long long j = k; j <= r; j += i)
  31. a[j - l + 1] = false;
  32. }
  33. }
  34.  
  35. for (long long i = l; i <= r; i++) {
  36. if (a[i - l + 1] && i != 1) cout << i << " ";
  37. }
  38.  
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
0