// Karol Kosinski 2024 #include <bits/stdc++.h> #define FOR(i,a,b) for(int i=(a),_b=(b);i<_b;++i) #define FR_(i,a,b) for(int i=(a),_b=(b);i<=_b;++i) #define FD_(i,b,a) for(int i=(b),_a=(a);i>=_a;--i) #define ALL(c) (c).begin(),(c).end() #define SIZE(c) int((c).size()) #define X first #define Y second #define endl '\n' #define NAM(x) #x,'=',x using namespace std; using LL = long long; using ULL = unsigned long long; using PII = pair<int, int>; using TIII = tuple<int, int, int>; template<class...T> void _cout(T...a){(cout<<...<<a);} #ifndef ENABLE_DEBUG #define DEB(k,p,f,x...) #else #define DEB(k,p,f,x...) {if(k)_cout("------",setw(4),__LINE__," : ",__FUNCTION__,endl);if(p)f(x);} #endif #define DEBF(f,x...) DEB(1,1,f,x) #define DEBL DEBF(void,0) #define DEBC(p,x...) DEB(0,p,_cout,x) #define DEBUG(x...) DEBC(1,x) #include "dzilib.h" using PLL = pair<LL, LL>; LL divs(LL limit) { if ( limit == 1 ) return 1; LL divisors = 2, i = 2; for ( ; i * i < limit; ++ i ) if ( limit % i == 0 ) divisors += 2; if ( limit == i * i ) ++ divisors; return divisors; } constexpr int MLNX = 1'000'000; constexpr int LIMIT = MLNX + 500; void print_mv(); // bool Exists[ MLNX + 1 ]; int DVS[ LIMIT + 1 ]; list<int> LE; void small_cases(int n, int t) { // DEBF( print_mv ); DEBL; FR_(i,1,LIMIT) { DVS[i] = divs(i); } while ( t -- ) { DEBL; FR_(i,1,MLNX) LE.push_back(i); int ind = 0; while ( LE.size() > 1 ) { int a = int(Ask(ind)); auto it = LE.begin(); while ( it != LE.end() ) { if ( DVS[ *it + ind ] != a ) { it = LE.erase(it); } else { // DEBC( t == 0, NAM( *it+ind ), endl ); ++ it; } } ++ ind; DEBUG( NAM(a), " ", NAM(LE.size()), endl ); } Answer(LE.front()); } } void testcase() { DEBL; int t = GetT(); LL n = GetN(); int q = GetQ(); LL c = GetC(); DEBUG( NAM(t), ' ', NAM(n), ' ', NAM(q), ' ', NAM(c), endl ); if ( n <= MLNX ) { small_cases( int(n), t ); return; } while ( t -- ) { Answer(1); } } int main() { // ios_base::sync_with_stdio(false); // cin.tie(nullptr); // DEBF( print_divs_squares_until, 1 << 20 ); // DEBF( print_divs_until, 1 << 20 ); testcase(); return 0; } using TUP = tuple<int, int, int, int, int, int>; constexpr int NX = (1 << 20) + 5; void print_mv() { constexpr int CVX = 2'000; map<TUP, int> MV; deque<LL> DQ; constexpr int LMT = 6; FOR(i,1,LMT) DQ.push_back( divs(i) ); FOR(i,LMT,NX) { if ( i - LMT + 1 > MLNX ) break; DQ.push_back( divs(i) ); ++ MV[ TUP( DQ[0], DQ[1], DQ[2], DQ[3], DQ[4], DQ[5] ) ]; DQ.pop_front(); } DEBUG( "MV size: ", SIZE(MV), endl ); int maxval = 0; vector<int> CV(CVX); for ( const auto& [ttt, val] : MV ) { const auto& [a, b, c, d, e, f] = ttt; ++ CV[val]; DEBUG( "( ", a, ", ", b, ", ", c, ", ", d, ", ", e, ", ", e, " ) : ", val, endl ); } FOR(i,1,CVX) { if ( CV[i] == 0 ) continue; DEBUG( NAM(i), "\t : " , setw(4), CV[i], endl ); } } // constexpr int VX = 2'000'005; // vector<LL> Vals[VX]; // void print_divs_until(LL x) // { // LL j = 1; // while ( j <= x ) // { // LL a = divs( j ); // Vals[a].push_back( j ); // DEBUG( NAM(j), "\t divs = ", setw(4), a, endl ); // ++ j; // } // FOR(i,1,VX) // { // if ( Vals[i].empty() ) continue; // DEBUG( NAM(i), " \t( " , setw(4), SIZE( Vals[i] ), " ) : " ); // for ( LL v : Vals[i] ) // { // DEBUG( v, " " ); // } // DEBUG( endl ); // } // } // void print_divs_squares_until(LL x) // { // LL j = 1; // while ( j * j <= x ) // { // LL a = divs( j * j ); // Vals[a].push_back( j ); // DEBUG( NAM(j), "\t divs = ", setw(4), a, endl ); // ++ j; // } // FOR(i,1,VX) // { // if ( Vals[i].empty() ) continue; // DEBUG( NAM(i), " \t( " , setw(4), SIZE( Vals[i] ), " ) : " ); // for ( LL v : Vals[i] ) // { // DEBUG( v, " " ); // } // DEBUG( endl ); // } // }
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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | // Karol Kosinski 2024 #include <bits/stdc++.h> #define FOR(i,a,b) for(int i=(a),_b=(b);i<_b;++i) #define FR_(i,a,b) for(int i=(a),_b=(b);i<=_b;++i) #define FD_(i,b,a) for(int i=(b),_a=(a);i>=_a;--i) #define ALL(c) (c).begin(),(c).end() #define SIZE(c) int((c).size()) #define X first #define Y second #define endl '\n' #define NAM(x) #x,'=',x using namespace std; using LL = long long; using ULL = unsigned long long; using PII = pair<int, int>; using TIII = tuple<int, int, int>; template<class...T> void _cout(T...a){(cout<<...<<a);} #ifndef ENABLE_DEBUG #define DEB(k,p,f,x...) #else #define DEB(k,p,f,x...) {if(k)_cout("------",setw(4),__LINE__," : ",__FUNCTION__,endl);if(p)f(x);} #endif #define DEBF(f,x...) DEB(1,1,f,x) #define DEBL DEBF(void,0) #define DEBC(p,x...) DEB(0,p,_cout,x) #define DEBUG(x...) DEBC(1,x) #include "dzilib.h" using PLL = pair<LL, LL>; LL divs(LL limit) { if ( limit == 1 ) return 1; LL divisors = 2, i = 2; for ( ; i * i < limit; ++ i ) if ( limit % i == 0 ) divisors += 2; if ( limit == i * i ) ++ divisors; return divisors; } constexpr int MLNX = 1'000'000; constexpr int LIMIT = MLNX + 500; void print_mv(); // bool Exists[ MLNX + 1 ]; int DVS[ LIMIT + 1 ]; list<int> LE; void small_cases(int n, int t) { // DEBF( print_mv ); DEBL; FR_(i,1,LIMIT) { DVS[i] = divs(i); } while ( t -- ) { DEBL; FR_(i,1,MLNX) LE.push_back(i); int ind = 0; while ( LE.size() > 1 ) { int a = int(Ask(ind)); auto it = LE.begin(); while ( it != LE.end() ) { if ( DVS[ *it + ind ] != a ) { it = LE.erase(it); } else { // DEBC( t == 0, NAM( *it+ind ), endl ); ++ it; } } ++ ind; DEBUG( NAM(a), " ", NAM(LE.size()), endl ); } Answer(LE.front()); } } void testcase() { DEBL; int t = GetT(); LL n = GetN(); int q = GetQ(); LL c = GetC(); DEBUG( NAM(t), ' ', NAM(n), ' ', NAM(q), ' ', NAM(c), endl ); if ( n <= MLNX ) { small_cases( int(n), t ); return; } while ( t -- ) { Answer(1); } } int main() { // ios_base::sync_with_stdio(false); // cin.tie(nullptr); // DEBF( print_divs_squares_until, 1 << 20 ); // DEBF( print_divs_until, 1 << 20 ); testcase(); return 0; } using TUP = tuple<int, int, int, int, int, int>; constexpr int NX = (1 << 20) + 5; void print_mv() { constexpr int CVX = 2'000; map<TUP, int> MV; deque<LL> DQ; constexpr int LMT = 6; FOR(i,1,LMT) DQ.push_back( divs(i) ); FOR(i,LMT,NX) { if ( i - LMT + 1 > MLNX ) break; DQ.push_back( divs(i) ); ++ MV[ TUP( DQ[0], DQ[1], DQ[2], DQ[3], DQ[4], DQ[5] ) ]; DQ.pop_front(); } DEBUG( "MV size: ", SIZE(MV), endl ); int maxval = 0; vector<int> CV(CVX); for ( const auto& [ttt, val] : MV ) { const auto& [a, b, c, d, e, f] = ttt; ++ CV[val]; DEBUG( "( ", a, ", ", b, ", ", c, ", ", d, ", ", e, ", ", e, " ) : ", val, endl ); } FOR(i,1,CVX) { if ( CV[i] == 0 ) continue; DEBUG( NAM(i), "\t : " , setw(4), CV[i], endl ); } } // constexpr int VX = 2'000'005; // vector<LL> Vals[VX]; // void print_divs_until(LL x) // { // LL j = 1; // while ( j <= x ) // { // LL a = divs( j ); // Vals[a].push_back( j ); // DEBUG( NAM(j), "\t divs = ", setw(4), a, endl ); // ++ j; // } // FOR(i,1,VX) // { // if ( Vals[i].empty() ) continue; // DEBUG( NAM(i), " \t( " , setw(4), SIZE( Vals[i] ), " ) : " ); // for ( LL v : Vals[i] ) // { // DEBUG( v, " " ); // } // DEBUG( endl ); // } // } // void print_divs_squares_until(LL x) // { // LL j = 1; // while ( j * j <= x ) // { // LL a = divs( j * j ); // Vals[a].push_back( j ); // DEBUG( NAM(j), "\t divs = ", setw(4), a, endl ); // ++ j; // } // FOR(i,1,VX) // { // if ( Vals[i].empty() ) continue; // DEBUG( NAM(i), " \t( " , setw(4), SIZE( Vals[i] ), " ) : " ); // for ( LL v : Vals[i] ) // { // DEBUG( v, " " ); // } // DEBUG( endl ); // } // } |