Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- const int YOLO = 900250;
- vector<ll> sv()
- {
- vector<bool> p(YOLO, 0);
- vector<ll> factors(YOLO, 1);
- for (ll i = 2; i < YOLO; ++i){
- if (p[i] == 0){
- for (ll j = i; j < YOLO; j += i){
- p[j] = 1;
- ll cnt = 0, temp = j;
- while (temp > 1 && temp % i == 0){
- ++cnt;
- temp /= i;
- }
- if (cnt > 0){
- // v[j].push_back({i,cnt});
- factors[j] *= (1ll + cnt);
- }
- }
- }
- }
- factors[0] = 0, factors[1] = 1;
- vector<ll> pre(YOLO, 0);
- for (int i = 1; i < YOLO; ++i){
- pre[i] = pre[i - 1] + factors[i];
- // cout<<i<<"-> "<<pre[i]<<endl;
- }
- // cout<<"y "<<pre.back()<<" y";
- // for(int i=2;i<YOLO;++i){
- // int tot = 1;
- // for(auto &x: v[i]){
- // tot *= (x.second+1);
- // }
- // factors[i] = tot;
- // }
- // for(int i=YOLO-30;i<YOLO;++i){
- // cout<<i<<" -> ";
- // for(auto &xx: v[i])
- // cout<<"{"<<xx.first<<","<<xx.second<<"} , ";
- // cout<<endl;
- // }
- // cout<<endl;
- // for(int i=YOLO-30;i<YOLO-1;++i){
- // cout<<i<<" _ "<<factors[i]<<endl;
- // }
- // for(int i=1;i<=30;++i){
- // cout<<i<<" _ "<<factors[i]<<endl;
- // }
- return pre;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
- int t;
- cin >> t;
- vector<ll> pre = sv();
- while (t--){
- ll k;
- cin >> k;
- ll l = 1, r = YOLO - 1, ans = -1, f = 0;
- while (l <= r){
- ll m = l + (r - l) / 2;
- if (pre[m] == k){
- f = 1;
- cout << m << '\n';
- break;
- }
- else if (pre[m] > k){
- r = m - 1, ans = m;
- }
- else{
- l = m + 1;
- }
- }
- if (f == 0){
- cout << ans << '\n';
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment