fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define all(v) v.begin(),v.end()
  5. typedef long long int ll;
  6.  
  7. vector<ll> g(ll l) {
  8. vector<bool> p(l+1,true);
  9. p[0]=false;
  10. p[1]=false;
  11. ll m=sqrt(l);
  12. for (ll x=2;x<=m;x++) {
  13. if (p[x]) {
  14. for (ll y=x*x;y<=l;y+=x) {
  15. p[y]=false;
  16.  
  17. }
  18.  
  19.  
  20. }
  21.  
  22. }
  23. vector<ll> r;
  24. for (ll z=0;z<=l;z++) {
  25. if (p[z]) {
  26.  
  27. r.push_back(z);
  28. }
  29. }
  30. return r;
  31. }
  32.  
  33. vector<ll> f(ll s,ll e) {
  34. vector<ll> r=g(e);
  35.  
  36. ll b=lower_bound(all(r),s)-r.begin();
  37. r.erase(r.begin(),r.begin()+b);
  38.  
  39. return r;
  40. }
  41.  
  42. int main() {
  43. ll a,b,c;
  44. vector<ll> d(1000070,0);
  45. a=1;
  46. c=100;
  47. b=c+1;
  48. vector<ll> e=f(a,b);
  49. for (auto x:e) {
  50. d[x]=1;
  51. cout<<x<<endl;
  52. }
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0.01s 11112KB
stdin
Standard input is empty
stdout
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
101