fork download
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3.  
  4. #define int int64_t
  5. #define trav(i, a) for(auto& i: a)
  6. #define all(a) a.begin(), a.end()
  7. #define rall(a) a.rbegin(), a.rend()
  8. #define si(a) ((int)(a).size())
  9. #define ins insert
  10. #define pb push_back
  11. #define mp make_pair
  12. #define f first
  13. #define s second
  14.  
  15. const int MOD = 1e9 + 7;
  16. const int INF = 1e18;
  17. const string nl = "\n";
  18.  
  19. struct timer {
  20. decltype(chrono::high_resolution_clock::now()) begin;
  21. void start() {
  22. begin = chrono::high_resolution_clock::now();
  23. }
  24. void end() {
  25. auto end = chrono::high_resolution_clock::now();
  26. auto duration = chrono::duration_cast<chrono::milliseconds>(end - begin).count();
  27. cerr << duration << "ms elapsed" << endl;
  28. }
  29. };
  30.  
  31. const int N = 1e8;
  32.  
  33. vector<bool> isp(N, true);
  34.  
  35. void sieve() {
  36. isp[0] = isp[1] = 0;
  37. for(int i = 2; i < N; ++i) {
  38. if(!isp[i]) {
  39. continue;
  40. }
  41. for(int j = i * i; j < N; j += i) {
  42. isp[j] = false;
  43. }
  44. }
  45. }
  46.  
  47. vector<bool> is_prime(N, true);
  48.  
  49. void sieve1() {
  50. is_prime[0] = is_prime[1] = 0;
  51. for(int i = 2; i < N; ++i) {
  52. for(int j = i * i; j < N; j += i) {
  53. is_prime[j] = false;
  54. }
  55. }
  56. }
  57.  
  58. int32_t main() {
  59. ios::sync_with_stdio(0);
  60. cin.tie(nullptr);
  61.  
  62. timer a;
  63. a.start();
  64. sieve();
  65. a.end();
  66. a.start();
  67. sieve1();
  68. a.end();
  69. }
  70.  
Success #stdin #stdout #stderr 4.7s 27416KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
731ms elapsed
4043ms elapsed