IMohammedNasr

Day 1 / D

Aug 18th, 2022 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5.  
  6. vector<ll> build;
  7.  
  8. int main(){
  9.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  10.   freopen("input.txt","r",stdin), freopen("output.txt", "w", stdout);
  11.     int TC = 1;
  12.     cin>>TC;
  13.     vector<bool> is_prime(1e7+5, true);
  14.     for (ll i = 2; i <= 1e7; i++) {
  15.     if (is_prime[i] && (ll)i * i <= 1e7) {
  16.         for (ll j = i * i; j <= 1e7; j += i)
  17.             is_prime[j] = false;
  18.         }
  19.     }
  20.     for(ll i=2; i<=1e7; i++){
  21.         if(is_prime[i])
  22.             build.push_back(i*i);
  23.     }
  24.     while(TC--){
  25.         ll n; cin>>n;
  26.  
  27.     // cout<<upper_bound(build.begin(),build.end(), n) - build.begin()<<'\n';
  28.     // or you can build it by yourself
  29.  
  30.     int l = 0, r = build.size() - 1, best = -1;
  31.     while(l <= r){
  32.       ll mid = l + (r - l ) / 2;
  33.       (build[mid] <= n ? l = mid + 1, best = mid : r = mid - 1);
  34.     }
  35.     cout<<best + 1<<'\n';
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment