Advertisement
tiom4eg

openol I 82

Jan 16th, 2023
1,036
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.18 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. // tiom4eg's precompiler options
  3. // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
  4. // IO settings
  5. #define fastIO ios_base::sync_with_stdio(false); cin.tie(0)
  6. // Quick types
  7. #define ll long long
  8. #define ld long double
  9. #define ull unsigned long long
  10. #define pii pair <int, int>
  11. #define vi vector <int>
  12. #define mi vector <vector <int>>
  13. // Quick functions
  14. #define endl "\n"
  15. #define F first
  16. #define S second
  17. #define all(a) a.begin(), a.end()
  18. #define sz(a) (int)(a.size())
  19. #define pb push_back
  20. #define mp make_pair
  21. // Quick fors
  22. #define FOR(i, a, b) for (int i = a; i < b; ++i)
  23. #define FORS(i, a, b, c) for (int i = a; i < b; i += c)
  24. #define RFOR(i, a, b) for (int i = a; i >= b; --i)
  25. #define EACH(e, a) for (auto& e : a)
  26. // Pragmas
  27. #ifndef TIOM4EG
  28. #pragma GCC optimize("O3,no-stack-protector") // let the chaos begin!
  29. #pragma GCC target("avx,avx2,popcnt,tune=native")
  30. #endif
  31. // PBDS
  32. /*#include <ext/pb_ds/assoc_container.hpp>
  33. #include <ext/pb_ds/tree_policy.hpp>
  34. #define ordered_set tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
  35. #define ook order_of_key
  36. #define fbo find_by_order
  37. using namespace __gnu_pbds;*/
  38. // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
  39. using namespace std;
  40. mt19937 rng(chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count());
  41. //#define int int64_t
  42. //const int INF = 1e9 + 7, INFLL = 1e13 + 7, MD = 998244353, MAX = 1 << 19, MOD = 1e9 + 7, LG = 30, B = 31, S = 10008;
  43. constexpr int32_t pr[96] = {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, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503};
  44. constexpr int64_t lim[95] = {750000000000000000, 500000000000000000, 300000000000000000, 214285714285714285, 136363636363636363, 115384615384615384, 88235294117647058, 78947368421052631, 65217391304347826, 51724137931034482, 48387096774193548, 40540540540540540, 36585365853658536, 34883720930232558, 31914893617021276, 28301886792452830, 25423728813559322, 24590163934426229, 22388059701492537, 21126760563380281, 20547945205479452, 18987341772151898, 18072289156626506, 16853932584269662, 15463917525773195, 14851485148514851, 14563106796116504, 14018691588785046, 13761467889908256, 13274336283185840, 11811023622047244, 11450381679389312, 10948905109489051, 10791366906474820, 10067114093959731, 9933774834437086, 9554140127388535, 9202453987730061, 8982035928143712, 8670520231213872, 8379888268156424, 8287292817679558, 7853403141361256, 7772020725388601, 7614213197969543, 7537688442211055, 7109004739336492, 6726457399103139, 6607929515418502, 6550218340611353, 6437768240343347, 6276150627615062, 6224066390041493, 5976095617529880, 5836575875486381, 5703422053231939, 5576208178438661, 5535055350553505, 5415162454873646, 5338078291814946, 5300353356890459, 5119453924914675, 4885993485342019, 4823151125401929, 4792332268370607, 4731861198738170, 4531722054380664, 4451038575667655, 4322766570605187, 4297994269340974, 4249291784702549, 4178272980501392, 4087193460490463, 4021447721179624, 3957783641160949, 3916449086161879, 3856041131105398, 3778337531486146, 3740648379052369, 3667481662591687, 3579952267303102, 3562945368171021, 3480278422273781, 3464203233256351, 3416856492027334, 3386004514672686, 3340757238307349, 3282275711159737, 3253796095444685, 3239740820734341, 3211991434689507, 3131524008350730, 3080082135523613, 3054989816700610, 3006012024048096};
  45. constexpr int32_t Z = 700000;
  46. int32_t s, b, pt;
  47. int64_t n, calc[35000000], aux[35000000];
  48.  
  49. #define SWAP(a, b) do { auto T = (a); a = b; b = T; } while (0)
  50. static void radix_sort_u32_multipass(int64_t *arr, int64_t *aux, size_t n, uint32_t keyshift) {
  51.     size_t cnt0[256] = { 0 };
  52.     size_t cnt1[256] = { 0 };
  53.     size_t cnt2[256] = { 0 };
  54.     size_t cnt3[256] = { 0 };
  55.     size_t i;
  56.     for (i = 0 ; i < n ; ++i) {
  57.         uint32_t k = *(arr + i) >> keyshift;
  58.         uint8_t k0 = (k >> 0) & 0xFF;
  59.         uint8_t k1 = (k >> 8) & 0xFF;
  60.         uint8_t k2 = (k >> 16) & 0xFF;
  61.         uint8_t k3 = (k >> 24) & 0xFF;
  62.         ++cnt0[k0];
  63.         ++cnt1[k1];
  64.         ++cnt2[k2];
  65.         ++cnt3[k3];
  66.     }
  67.     size_t a0 = 0;
  68.     size_t a1 = 0;
  69.     size_t a2 = 0;
  70.     size_t a3 = 0;
  71.     for (int j = 0 ; j < 256 ; ++j) {
  72.         size_t b0 = cnt0[j];
  73.         size_t b1 = cnt1[j];
  74.         size_t b2 = cnt2[j];
  75.         size_t b3 = cnt3[j];
  76.         cnt0[j] = a0;
  77.         cnt1[j] = a1;
  78.         cnt2[j] = a2;
  79.         cnt3[j] = a3;
  80.         a0 += b0;
  81.         a1 += b1;
  82.         a2 += b2;
  83.         a3 += b3;
  84.     }
  85.     for (i = 0 ; i < n ; ++i) {
  86.         uint32_t k = *(arr + i) >> keyshift;
  87.         uint8_t k0 = (k >> 0) & 0xFF;
  88.         size_t dst = cnt0[k0]++;
  89.         aux[dst] = arr[i];
  90.     }
  91.     SWAP(arr, aux);
  92.     for (i = 0 ; i < n ; ++i) {
  93.         uint32_t k = *(arr + i) >> keyshift;
  94.         uint8_t k1 = (k >> 8) & 0xFF;
  95.         size_t dst = cnt1[k1]++;
  96.         aux[dst] = arr[i];
  97.     }
  98.     SWAP(arr, aux);
  99.     for (i = 0 ; i < n ; ++i) {
  100.         uint32_t k = *(arr + i) >> keyshift;
  101.         uint8_t k2 = (k >> 16) & 0xFF;
  102.         size_t dst = cnt2[k2]++;
  103.         aux[dst] = arr[i];
  104.     }
  105.     SWAP(arr, aux);
  106.     for (i = 0 ; i < n ; ++i) {
  107.         uint32_t k = *(arr + i) >> keyshift;
  108.         uint8_t k3 = (k >> 24) & 0xFF;
  109.         size_t dst = cnt3[k3]++;
  110.         aux[dst] = arr[i];
  111.     }
  112. }
  113.  
  114. int32_t dp[95][Z + 1];
  115.  
  116. int64_t traverse(int64_t x, int32_t i) {
  117.     if (x <= pr[i]) return x;
  118.     if (i == 9) return upper_bound(calc, calc + pt, x) - calc;
  119.     if (x <= Z && dp[i][x]) return dp[i][x];
  120.     int64_t r = 0, c = x;
  121.     while (c) {
  122.         r += (i ? traverse(c, i - 1) : 1);
  123.         c /= pr[i];
  124.     }
  125.     if (x <= Z) dp[i][x] = r;
  126.     return r;
  127. }
  128.  
  129. void precalc(int64_t x, int32_t i) {
  130.     if (i == -1) return void(calc[pt++] = x);
  131.     precalc(x, i - 1);
  132.     while (x <= lim[i] && x * pr[i] <= n) {
  133.         x *= pr[i];
  134.         precalc(x, i - 1);
  135.     }
  136. }
  137.  
  138. signed main() {
  139.     fastIO;
  140.     FOR(i, 0, 95) dp[i][1] = 1;
  141.     cin >> n >> b;
  142.     while (pr[s] <= b) ++s;
  143.     precalc(1, 9);
  144.     radix_sort_u32_multipass(calc, aux, pt, 0);
  145.     radix_sort_u32_multipass(calc, aux, pt, 32);
  146.     cout << traverse(n, s - 1);
  147. }
  148.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement