Advertisement
Ahmed_Negm

E

Apr 14th, 2024
791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define nl "\n"
  6.  
  7. void files(){
  8.     ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
  9.     #ifndef ONLINE_JUDGE
  10.         freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  11.     #endif
  12. }
  13.  
  14. const int N = 1e8+1;
  15. ll spf[N];
  16. ll level[N];
  17. map<ll,set<ll>> inserted;
  18.  
  19. void sieve(){
  20.     for(ll i = 1; i < N; i++) spf[i] = i;
  21.     for(ll i = 2; i*i < N; i++){
  22.         if(spf[i] == i){
  23.             for(ll j = i*i; j < N; j += i){
  24.                 if(spf[j] == j) spf[j] = i;
  25.             }
  26.         }
  27.     }
  28.  
  29.     for(ll i = 2; i < N; i++){
  30.         ll x = i;
  31.         set<ll> st;
  32.         while(x != 1){
  33.             st.insert(spf[x]);
  34.             x /= spf[x];
  35.         }
  36.         level[i] = (int)st.size();
  37.     }
  38.  
  39. }
  40.  
  41.  
  42. void solve(){
  43.     ll q; cin>>q;
  44.  
  45.  
  46.     for(ll i = 0; i < q; i++){
  47.         char c; cin>>c;
  48.         ll x; cin>>x;
  49.         if(c=='>'){
  50.             inserted[level[x]].insert(x);
  51.         }else{
  52.             if(inserted[level[x]].size() == 0){
  53.                 cout<<-1<<nl;
  54.             }else
  55.                 cout<<*inserted[x].begin()<<nl;
  56.         }
  57.     }
  58.  
  59.  
  60. }
  61.  
  62. int main(){
  63.     files();
  64.     sieve();
  65.     int t = 1;
  66.     // cin>>t;
  67.     while(t--) solve();
  68.  
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement