// Author: Kajetan Ramsza #include "bits/stdc++.h" #include "dzilib.h" using namespace std; #define rep(i, a, b) for(int i = (a); i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; template<typename F, typename S> ostream& operator<<(ostream& os, const pair<F, S> &p) { return os<<"("<<p.first<<", "<<p.second<<")"; } template<typename T> ostream &operator<<(ostream & os, const vector<T> &v) { os << "{"; typename vector< T > :: const_iterator it; for( it = v.begin(); it != v.end(); it++ ) { if( it != v.begin() ) os << ", "; os << *it; } return os << "}"; } template<typename T> ostream &operator << ( ostream & os, const set< T > &v ) { os << "["; typename set< T > :: const_iterator it; for ( it = v.begin(); it != v.end(); it++ ) { if( it != v.begin() ) os << ", "; os << *it; } return os << "]"; } template < typename F, typename S > ostream &operator << ( ostream & os, const map< F, S > &v ) { os << "["; typename map< F , S >::const_iterator it; for( it = v.begin(); it != v.end(); it++ ) { if( it != v.begin() ) os << ", "; os << it -> first << " = " << it -> second ; } return os << "]"; } void dbg_out() { cerr<<'\n'; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr<<' '<<H; dbg_out(T...); } #ifdef DEBUG #define dbg(...) cerr<<"(" << #__VA_ARGS__ <<"):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif const ll mod1 = ll(1e9) + 7; const ll mod2 = ll(1e9) + 9; const ll base = 1009; const ll l = 30; map<pair<ll,ll>, int> hash_map; const int maxn = 1e6 + l + 7; // const int maxn = 1001 + l + 7; ll num[maxn]; int factor[maxn]; int calc(int v) { int res = 1; while(v > 1) { assert(v > 0 && v < maxn); int p = factor[v]; int e = 0; while(v % p == 0) e++, v /= p; res *= (e+1); } return res; } void preprocess() { iota(factor, factor+maxn, 0); rep(i,2,maxn) { if(factor[i] != i) continue; for(ll j=(ll)i*i;j<maxn;j+=i) factor[j] = i; } rep(i,1,maxn) num[i] = calc(i); ll h1 = 0, h2 = 0, power1 = 1, power2 = 1; rep(i,0,l) { h1 = (h1 * base + num[i]) % mod1; h2 = (h2 * base + num[i]) % mod2; power1 = power1 * base % mod1; power2 = power2 * base % mod2; } rep(i,0,maxn - l) { hash_map[{h1, h2}] = i; h1 = (h1 * base + mod1 - power1 * num[i] % mod1 + num[i+l]) % mod1; h2 = (h2 * base + mod2 - power2 * num[i] % mod2 + num[i+l]) % mod2; } // dbg(hash_map); } void solve() { ll h1 = 0, h2 = 0; rep(i,0,l) { ll div = Ask(i); h1 = (h1 * base + div) % mod1; h2 = (h2 * base + div) % mod2; } dbg(h1, h2); Answer(hash_map[{h1, h2}]); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); preprocess();; int t = GetT(); // int q = GetQ(); // ll c = GetC(); // ll n = GetN(); while(t--) { solve(); } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | // Author: Kajetan Ramsza #include "bits/stdc++.h" #include "dzilib.h" using namespace std; #define rep(i, a, b) for(int i = (a); i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; template<typename F, typename S> ostream& operator<<(ostream& os, const pair<F, S> &p) { return os<<"("<<p.first<<", "<<p.second<<")"; } template<typename T> ostream &operator<<(ostream & os, const vector<T> &v) { os << "{"; typename vector< T > :: const_iterator it; for( it = v.begin(); it != v.end(); it++ ) { if( it != v.begin() ) os << ", "; os << *it; } return os << "}"; } template<typename T> ostream &operator << ( ostream & os, const set< T > &v ) { os << "["; typename set< T > :: const_iterator it; for ( it = v.begin(); it != v.end(); it++ ) { if( it != v.begin() ) os << ", "; os << *it; } return os << "]"; } template < typename F, typename S > ostream &operator << ( ostream & os, const map< F, S > &v ) { os << "["; typename map< F , S >::const_iterator it; for( it = v.begin(); it != v.end(); it++ ) { if( it != v.begin() ) os << ", "; os << it -> first << " = " << it -> second ; } return os << "]"; } void dbg_out() { cerr<<'\n'; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr<<' '<<H; dbg_out(T...); } #ifdef DEBUG #define dbg(...) cerr<<"(" << #__VA_ARGS__ <<"):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif const ll mod1 = ll(1e9) + 7; const ll mod2 = ll(1e9) + 9; const ll base = 1009; const ll l = 30; map<pair<ll,ll>, int> hash_map; const int maxn = 1e6 + l + 7; // const int maxn = 1001 + l + 7; ll num[maxn]; int factor[maxn]; int calc(int v) { int res = 1; while(v > 1) { assert(v > 0 && v < maxn); int p = factor[v]; int e = 0; while(v % p == 0) e++, v /= p; res *= (e+1); } return res; } void preprocess() { iota(factor, factor+maxn, 0); rep(i,2,maxn) { if(factor[i] != i) continue; for(ll j=(ll)i*i;j<maxn;j+=i) factor[j] = i; } rep(i,1,maxn) num[i] = calc(i); ll h1 = 0, h2 = 0, power1 = 1, power2 = 1; rep(i,0,l) { h1 = (h1 * base + num[i]) % mod1; h2 = (h2 * base + num[i]) % mod2; power1 = power1 * base % mod1; power2 = power2 * base % mod2; } rep(i,0,maxn - l) { hash_map[{h1, h2}] = i; h1 = (h1 * base + mod1 - power1 * num[i] % mod1 + num[i+l]) % mod1; h2 = (h2 * base + mod2 - power2 * num[i] % mod2 + num[i+l]) % mod2; } // dbg(hash_map); } void solve() { ll h1 = 0, h2 = 0; rep(i,0,l) { ll div = Ask(i); h1 = (h1 * base + div) % mod1; h2 = (h2 * base + div) % mod2; } dbg(h1, h2); Answer(hash_map[{h1, h2}]); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); preprocess();; int t = GetT(); // int q = GetQ(); // ll c = GetC(); // ll n = GetN(); while(t--) { solve(); } return 0; } |