aj30

Untitled

May 29th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.16 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. typedef long long ll;
  5. const int YOLO = 900250;
  6. vector<ll> sv()
  7. {
  8.     vector<bool> p(YOLO, 0);
  9.     vector<ll> factors(YOLO, 1);
  10.    
  11.     for (ll i = 2; i < YOLO; ++i){
  12.         if (p[i] == 0){
  13.             for (ll j = i; j < YOLO; j += i){
  14.                 p[j] = 1;
  15.                 ll cnt = 0, temp = j;
  16.                 while (temp > 1 && temp % i == 0){
  17.                     ++cnt;
  18.                     temp /= i;
  19.                 }
  20.                 if (cnt > 0){
  21.                     // v[j].push_back({i,cnt});
  22.                     factors[j] *= (1ll + cnt);
  23.                 }
  24.             }
  25.         }
  26.     }
  27.     factors[0] = 0, factors[1] = 1;
  28.     vector<ll> pre(YOLO, 0);
  29.     for (int i = 1; i < YOLO; ++i){
  30.         pre[i] = pre[i - 1] + factors[i];
  31.         // cout<<i<<"-> "<<pre[i]<<endl;
  32.     }
  33.     // cout<<"y "<<pre.back()<<" y";
  34.     // for(int i=2;i<YOLO;++i){
  35.     //     int tot = 1;
  36.     //     for(auto &x: v[i]){
  37.     //         tot *= (x.second+1);
  38.     //     }
  39.     //     factors[i] = tot;
  40.     // }
  41.    
  42.     // for(int i=YOLO-30;i<YOLO;++i){
  43.     //     cout<<i<<" -> ";
  44.     //     for(auto &xx: v[i])
  45.     //         cout<<"{"<<xx.first<<","<<xx.second<<"} , ";
  46.     //     cout<<endl;
  47.     // }
  48.     // cout<<endl;
  49.     // for(int i=YOLO-30;i<YOLO-1;++i){
  50.     //     cout<<i<<" _ "<<factors[i]<<endl;
  51.     // }
  52.     // for(int i=1;i<=30;++i){
  53.     //     cout<<i<<" _ "<<factors[i]<<endl;
  54.     // }
  55.     return pre;
  56. }
  57.  
  58. int main()
  59. {
  60.     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  61.     int t;
  62.     cin >> t;
  63.     vector<ll> pre = sv();
  64.    
  65.     while (t--){
  66.         ll k;
  67.         cin >> k;
  68.         ll l = 1, r = YOLO - 1, ans = -1, f = 0;
  69.         while (l <= r){
  70.             ll m = l + (r - l) / 2;
  71.             if (pre[m] == k){
  72.                 f = 1;
  73.                 cout << m << '\n';
  74.                 break;
  75.             }
  76.             else if (pre[m] > k){
  77.                 r = m - 1, ans = m;
  78.             }
  79.             else{
  80.                 l = m + 1;
  81.             }
  82.         }
  83.         if (f == 0){
  84.             cout << ans << '\n';
  85.         }
  86.  
  87.     }
  88.     return 0;
  89. }
Add Comment
Please, Sign In to add comment