// 入力制約/フォーマットチェック #ifndef INCLUDE_MODE #define INCLUDE_MODE // #define REACTIVE #define USE_GETLINE #endif #ifdef INCLUDE_MAIN void Solve() { CEXPR( int , bound_N , 3e6 ); CEXPR( ll , bound_K , 1e18 ); GETLINE_COUNT_ASSERT( NK_str , ' ' , 2 ); STOI( NK_str , N , 1 , bound_N ); STOI( NK_str , K , 1 , bound_K ); CEXPR( int , val_limit , 1002 ); static HeapPrimeEnumeration pe{ val_limit }; if( K == 1 ){ RETURN( N ); } int P = 100003; vector> div = TotalEnumerateDivisor( P ); vector C( P ); FOR( i , 1 , P ){ C[i] = Sum( div[i] ) % P; } LoopDetection ldt{ Sum( EnumerateDivisor( pe , N ) ) % P , [&]( const int& i ){ return C[i]; } }; RETURN( ldt.IteratedComposition( K - 2 ) ); } REPEAT_MAIN(1); #else // INCLUDE_MAIN #ifdef INCLUDE_LIBRARY // https://github.com/p-adic/cpp // VVV ライブラリは以下に挿入する。 /* 圧縮用 */ #define TE template #define TY typename #define US using #define ST static #define AS assert #define IN inline #define CL class #define PU public #define OP operator #define CE constexpr #define CO const #define NE noexcept #define RE return #define WH while #define VO void #define VE vector #define LI list #define BE begin #define EN end #define SZ size #define LE length #define PW Power #define MO move #define TH this #define CRI CO int& #define CRUI CO uint& #define CRL CO ll& #define VI virtual #define IS basic_istream #define OS basic_ostream #define ST_AS static_assert #define reMO_CO remove_const #define is_COructible_v is_constructible_v #define rBE rbegin // CEXPRがCEに依存しているので削除しない。 // redefinitionを避けるため圧縮元はincludeしない。 TE CL PrimeEnumeration{PU:bool m_is_composite[val_limit];int m_val[le_max];int m_le;CE PrimeEnumeration();IN CRI OP[](CRI i)CO;CE CRI Get(CRI i)CO;CE CO bool& IsComposite(CRI n)CO;CE CRI length()CO NE;}; TE CE PrimeEnumeration::PrimeEnumeration():m_is_composite(),m_val(),m_le(0){for(int i = 2;i < val_limit;i++){if(! m_is_composite[i]){for(ll j = ll(i)* i;j < val_limit;j += i){m_is_composite[j]= true;}m_val[m_le++]= i;if(m_le >= le_max){break;}}}}TE IN CRI PrimeEnumeration::OP[](CRI i)CO{AS(0 <= i && i < m_le);RE m_val[i];}TE CE CRI PrimeEnumeration::Get(CRI i)CO{RE m_val[i];}TE CE CO bool& PrimeEnumeration::IsComposite(CRI n)CO{RE m_is_composite[n];}TE CE CRI PrimeEnumeration::length()CO NE{RE m_le;} CL HeapPrimeEnumeration{PU:int m_val_limit;VE m_is_composite;VE m_val;int m_le;IN HeapPrimeEnumeration(CRI val_limit);IN CRI OP[](CRI i)CO;IN CRI Get(CRI i)CO;IN bool IsComposite(CRI n)CO;IN CRI length()CO NE;}; IN HeapPrimeEnumeration::HeapPrimeEnumeration(CRI val_limit):m_val_limit(val_limit),m_is_composite(m_val_limit),m_val(),m_le(0){for(int i = 2;i < m_val_limit;i++){if(! m_is_composite[i]){for(ll j = ll(i)* i;j < val_limit;j += i){m_is_composite[j]= true;}m_val.push_back(i);}}m_le = m_val.SZ();}IN CRI HeapPrimeEnumeration::OP[](CRI i)CO{AS(0 <= i && i < m_le);RE m_val[i];}IN CRI HeapPrimeEnumeration::Get(CRI i)CO{RE OP[](i);}IN bool HeapPrimeEnumeration::IsComposite(CRI n)CO{AS(0 <= n && n < m_val_limit);RE m_is_composite[n];}IN CRI HeapPrimeEnumeration::length()CO NE{RE m_le;} TE auto CheckPE(CO PE& pe)-> decltype(pe.IsComposite(0),true_type());TE false_type CheckPE(...);TE CE bool IsPE = decltype(CheckPE(declval()))(); TE CL LeastDivisor{PU:int m_val[val_limit];CE LeastDivisor()NE;IN CRI OP[](CRI i)CO;CE CRI Get(CRI i)CO;CE int length()CO NE;}; TE CE LeastDivisor::LeastDivisor()NE:m_val{}{for(int d = 2;d < val_limit;d++){if(m_val[d]== 0){for(int n = d;n < val_limit;n += d){m_val[n]== 0?m_val[n]= d:d;}}}}TE IN CRI LeastDivisor::OP[](CRI i)CO{AS(0 <= i && i < val_limit);RE m_val[i];}TE CE CRI LeastDivisor::Get(CRI i)CO{RE m_val[i];}TE CE int LeastDivisor::length()CO NE{RE val_limit;} CL HeapLeastDivisor{PU:int m_val_limit;VE m_val;IN HeapLeastDivisor(CRI val_limit)NE;IN CRI OP[](CRI i)CO;IN CRI Get(CRI i)CO;IN CRI length()CO NE;}; IN HeapLeastDivisor::HeapLeastDivisor(CRI val_limit)NE:m_val_limit(val_limit),m_val(m_val_limit){for(int d = 2;d < m_val_limit;d++){if(m_val[d]== 0){for(int n = d;n < m_val_limit;n += d){m_val[n]== 0?m_val[n]= d:d;}}}}IN CRI HeapLeastDivisor::OP[](CRI i)CO{AS(0 <= i && i < m_val_limit);RE m_val[i];}IN CRI HeapLeastDivisor::Get(CRI i)CO{RE m_val[i];}IN CRI HeapLeastDivisor::length()CO NE{RE m_val_limit;} TE auto PrimeFactorisation(CO PE& pe,INT n)-> enable_if_t,pair,VE>>{AS(n > 0);VE P{};VE E{};CRI le = pe.length();for(int i = 0;i < le;i++){auto& p = pe[i];if(n % p == 0){int e = 1;WH((n /= p)% p == 0){e++;}P.push_back(p);E.push_back(e);}else if(n / p < p){break;}}if(n != 1){P.push_back(n);E.push_back(1);}RE{MO(P),MO(E)};}TE auto PrimeFactorisation(CO LD& ld,int n)-> enable_if_t,pair,VE>>{AS(n > 0);VE P{};VE E{};if(n > 1){P.push_back(ld[n]);E.push_back(1);n /= ld[n];}WH(n > 1){if(P.back()!= ld[n]){P.push_back(ld[n]);E.push_back(1);}else{E.back()++;}n /= ld[n];}RE{MO(P),MO(E)};}TE auto PrimePowerFactorisation(CO PE& pe,INT n)-> enable_if_t,tuple,VE,VE>>{AS(n > 0);VE P{};VE E{};VE Q{};CRI le = pe.length();for(int i = 0;i < le;i++){auto& p = pe[i];if(n % p == 0){int e = 1;INT q = p;WH((n /= p)% p == 0){e++;q *= p;}P.push_back(p);E.push_back(e);Q.push_back(q);}else if(n / p < p){break;}}if(n != 1){P.push_back(n);E.push_back(1);Q.push_back(n);}RE{MO(P),MO(E),MO(Q)};}TE auto PrimePowerFactorisation(CO LD& ld,int n)-> enable_if_t,tuple,VE,VE>>{AS(n > 0);VE P{};VE E{};VE Q{};if(n > 1){P.push_back(ld[n]);E.push_back(1);Q.push_back(ld[n]);n /= ld[n];}WH(n > 1){if(P.back()!= ld[n]){P.push_back(ld[n]);E.push_back(1);Q.push_back(ld[n]);}else{Q.back()*= ld[n];E.back()++;}n /= ld[n];}RE{MO(P),MO(E),MO(Q)};} TE INT CountDivisorBody(VE& E)NE{CO int LE = E.SZ();INT AN = 1;for(int i = 0;i < LE;i++){AN *= ++E[i];}RE AN;}TE INT CountDivisor(CO PE& pe,INT n)NE{auto[P,E]= PrimeFactorisation(pe,MO(n));RE CountDivisorBody(E);} TE VE EnumerateDivisorBody(CO VE& P,VE& E){CO int le = P.SZ();VE AN(CountDivisorBody(E),INT(1));int SZ = 1;for(int i = 0;i < le;i++){auto& P_i = P[i];auto& E_i = E[i];INT q = 1;int j_shift = 0;for(int e = 1;e < E_i;e++){q *= P_i;j_shift += SZ;for(int j = 0;j < SZ;j++){AN[j + j_shift]= AN[j]* q;}}SZ *= E_i;}RE AN;}TE VE EnumerateDivisor(CO PE& pe,INT n){auto[P,E]= PrimeFactorisation(pe,MO(n));RE EnumerateDivisorBody(P,E);}TE VE EnumerateSquareFreeDivisorBody(CO VE& P){CO int le = P.SZ();CO int SZ = 1 << le;VE AN(SZ,INT(1));for(int i = 0;i < le;i++){CO int s = 1 << i;for(int j = s;j < SZ;(++j)|= s){AN[j]*= P[i];}}RE AN;}TE VE EnumerateSquareFreeDivisor(CO PE& pe,INT n){auto[P,E]= PrimeFactorisation(pe,MO(n));RE EnumerateSquareFreeDivisorBody(P);}TE VE> TotalEnumerateDivisor(CO INT& n_max)NE{VE> AN(n_max + 1);for(INT d = 1;d <= n_max;d++){for(INT n = d;n <= n_max;n += d){AN[n].push_back(d);}}RE AN;}TE VE TotalEnumerateDivisor(CO INT& n_max,FUNC f,CO U& init)NE{ST_AS(is_invocable_r_v);VE AN(n_max + 1,init);for(INT d = 1;d <= n_max;d++){for(INT n = 0;n <= n_max;n += d){AN[n]= f(MO(AN[n]),d);}}RE AN;} template class LoopDetection_Body { private: T m_init; F m_f; int m_search_max; protected: // 像の要素数 int m_length; // ループ始点 int m_loop_start; // ループ長取得 int m_loop_length; public: inline LoopDetection_Body( const T& init , F f , const int& search_max ); template T IteratedComposition( const INT& n ); // 像の要素数取得 inline const int& GetLength() noexcept; // ループ始点取得 inline const int& GetLoopStart() noexcept; // ループ長取得 inline const int& GetLoopLength() noexcept; private: inline void SetInit(); inline void SearchLoop(); virtual T e( const int& i ) = 0; virtual int e_inv( const T& t ) = 0; virtual void SetValue( const int& i ) = 0; virtual const int& GetValue( const int& i ) = 0; }; template class ValueCalculatorForLoopDetection : public LoopDetection_Body { private: // m_value[n]にf^n(init)を格納する。 vector m_value; // m_value_inv[i]にf^n(init)=iとなる最小のnを格納する。 unordered_map m_value_inv; public: inline ValueCalculatorForLoopDetection( const T& init , F f , const int& search_max ); private: // f^0(init),...,f^n(init)までを既に計算した状態でf^{n+1}(init)=iと記録する。 void SetValue( const int& i ); // f^i(init)を返す。 int& RefValue( const int& i ); // f^i(init)を返す。 const int& GetValue( const int& i ); // f^n(init)=iとなる最小のnが見付かっていればそれを、見付かっていなければ-1を返す。 int& RefValue_inv( const int& i ); }; template class LoopDetection : public ValueCalculatorForLoopDetection { public: inline LoopDetection( const int& init , F f , const int& search_max = -1 ); private: inline int e( const int& i ); inline int e_inv( const int& t ); }; template class MemorisationLoopDetection : public LoopDetection_Body { private: // m_memory[t]にf^n(init)=tとなる最小のnを格納する。 Map m_memory; // m_memory_inv[n]にf^n(init)を格納する。 vector m_memory_inv; // つまりf^n自体をメモ化番号付けに流用する。だからGetValueが恒等関数になる。 public: inline MemorisationLoopDetection( const T& init , F f , const int& search_max = -1 ); inline T e( const int& i ); inline int e_inv( const T& t ); // 何もしない。 void SetValue( const int& i ); // iを返す。 const int& GetValue( const int& i ); }; template class EnumerationLoopDetection : public ValueCalculatorForLoopDetection { private: Enum_T m_enum_T; Enum_T_inv m_enum_T_inv; public: inline EnumerationLoopDetection( const T& init , Enum_T enum_T , Enum_T_inv enum_T_inv , F f , const int& search_max = -1 ); private: inline T e( const int& i ); inline int e_inv( const T& t ); }; template inline LoopDetection_Body::LoopDetection_Body( const T& init , F f , const int& search_max ) : m_init( init ) , m_f( move( f ) ) , m_search_max( search_max ) , m_length() , m_loop_start( -1 ) , m_loop_length( -1 ) { static_assert( is_invocable_r_v ); } template inline ValueCalculatorForLoopDetection::ValueCalculatorForLoopDetection( const T& init , F f , const int& search_max ) : LoopDetection_Body( init , move( f ) , search_max ) , m_value() , m_value_inv() {} template inline LoopDetection::LoopDetection( const int& init , F f , const int& search_max ) : ValueCalculatorForLoopDetection( init , move( f ) , search_max ) {} template inline MemorisationLoopDetection::MemorisationLoopDetection( const T& init , F f , const int& search_max ) : LoopDetection_Body( init , move( f ) , search_max ) , m_memory() , m_memory_inv() {} template inline EnumerationLoopDetection::EnumerationLoopDetection( const T& init , Enum_T enum_T , Enum_T_inv enum_T_inv , F f , const int& search_max ) : ValueCalculatorForLoopDetection( init , move( f ) , search_max ) , m_enum_T( enum_T ) , m_enum_T_inv( enum_T_inv ) { static_assert( is_invocable_r_v && is_invocable_r_v ); } template template T LoopDetection_Body::IteratedComposition( const INT& n ) { if( m_length == 0 ){ SetInit(); } if( n < m_length ){ return e( GetValue( n ) ); } if( m_loop_start != -1 ){ return e( GetValue( m_loop_start + ( n - m_loop_start ) % m_loop_length ) ); } SetValue( e_inv( m_f( e( GetValue( m_length - 1 ) ) ) ) ); return IteratedComposition( n ); } template inline const int& LoopDetection_Body::GetLength() noexcept { if( m_loop_length == -1 ){ SearchLoop(); } return m_length; } template inline const int& LoopDetection_Body::GetLoopStart() noexcept { if( m_loop_start == -1 ){ SearchLoop(); } return m_loop_start; } template inline const int& LoopDetection_Body::GetLoopLength() noexcept { if( m_loop_length == -1 ){ SearchLoop(); } return m_loop_length; } template inline void LoopDetection_Body::SetInit() { assert( m_length == 0 ); SetValue( e_inv( m_init ) ); } template inline void LoopDetection_Body::SearchLoop() { assert( m_loop_length == -1 ); int n = 0; while( m_loop_length == -1 && ( m_search_max == -1 || n <= m_search_max ) ){ IteratedComposition( n++ ); } } template inline int LoopDetection::e( const int& i ) { return i; } template inline T MemorisationLoopDetection::e( const int& i ) { using base = LoopDetection_Body; assert( i < base::m_length ); return m_memory_inv[i]; } template inline T EnumerationLoopDetection::e( const int& i ) { return m_enum_T( i ); } template inline int LoopDetection::e_inv( const int& t ) { return t; } template inline int MemorisationLoopDetection::e_inv( const T& t ) { using base = LoopDetection_Body; if( m_memory.count( t ) == 0 ){ m_memory_inv.push_back( t ); return m_memory[t] = base::m_length++; } base::m_loop_length = base::m_length - ( base::m_loop_start = m_memory[t] ); return base::m_loop_start; } template inline int EnumerationLoopDetection::e_inv( const T& t ) { return m_enum_T_inv( t ); } template inline void ValueCalculatorForLoopDetection::SetValue( const int& i ) { using base = LoopDetection_Body; int& m_value_inv_i = RefValue_inv( i ); if( m_value_inv_i != -1 ){ base::m_loop_length = base::m_length - ( base::m_loop_start = m_value_inv_i ); } else { RefValue( base::m_length ) = i; m_value_inv_i = base::m_length++; } return; } template inline void MemorisationLoopDetection::SetValue( const int& i ) {} template inline int& ValueCalculatorForLoopDetection::RefValue( const int& i ) { const int size = m_value.size(); if( size <= i ){ assert( size == i ); m_value.push_back( -1 ); } return m_value[i]; } template inline const int& ValueCalculatorForLoopDetection::GetValue( const int& i ) { return RefValue( i ); } template inline const int& MemorisationLoopDetection::GetValue( const int& i ) { return i; } template inline int& ValueCalculatorForLoopDetection::RefValue_inv( const int& i ) { if( m_value_inv.count( i ) == 0 ){ return m_value_inv[i] = -1; } return m_value_inv[i]; } // AAA ライブラリは以上に挿入する。 #define INCLUDE_MAIN #include __FILE__ #else // INCLUDE_LIBRARY #ifdef DEBUG #define _GLIBCXX_DEBUG #define SIGNAL signal( SIGABRT , &AlertAbort ); #define DEXPR( LL , BOUND , VALUE1 , VALUE2 ) CEXPR( LL , BOUND , VALUE2 ) #define ASSERT( A , MIN , MAX ) CERR( "ASSERTチェック: " , ( MIN ) , ( ( MIN ) <= A ? "<=" : ">" ) , A , ( A <= ( MAX ) ? "<=" : ">" ) , ( MAX ) ); assert( ( MIN ) <= A && A <= ( MAX ) ) #define CERR( ... ) VariadicCout( cerr , __VA_ARGS__ ) << endl #define CERRNS( ... ) VariadicCoutNonSep( cerr , __VA_ARGS__ ) #define CERR_A( I , N , A ) CoutArray( cerr , I , N , A ) << endl int exec_mode = 0; #else #pragma GCC optimize ( "O3" ) #pragma GCC optimize ( "unroll-loops" ) #pragma GCC target ( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" ) #define SIGNAL #define DEXPR( LL , BOUND , VALUE1 , VALUE2 ) CEXPR( LL , BOUND , VALUE1 ) #define ASSERT( A , MIN , MAX ) AS( ( MIN ) <= A && A <= ( MAX ) ) #define CERR( ... ) #define CERRNS( ... ) #define CERR_A( I , N , A ) #endif #ifdef REACTIVE #ifdef DEBUG #define RSET( A , ... ) A = __VA_ARGS__ #else #define RSET( A , ... ) cin >> A #endif #define RCIN( LL , A , ... ) LL A; RSET( A , __VA_ARGS__ ) #define ENDL endl #else #define ENDL "\n" #endif #ifdef USE_GETLINE #define SET_SEPARATE( SEPARATOR , ... ) VariadicGetline( cin , SEPARATOR , __VA_ARGS__ ) #define SET( ... ) SET_SEPARATE( '\n' , __VA_ARGS__ ) #define GETLINE_SEPARATE( SEPARATOR , ... ) string __VA_ARGS__; SET_SEPARATE( SEPARATOR , __VA_ARGS__ ) #define GETLINE( ... ) GETLINE_SEPARATE( '\n' , __VA_ARGS__ ) #define FINISH_MAIN GETLINE( test_case_num_str ); test_case_num = stoi( test_case_num_str ); ASSERT( test_case_num , 1 , test_case_num_bound ); } REPEAT( test_case_num ){ Solve(); } CHECK_REDUNDANT_INPUT; } #else #define SET( ... ) VariadicCin( cin , __VA_ARGS__ ) #define CIN( LL , ... ) LL __VA_ARGS__; SET( __VA_ARGS__ ) #define SET_A( I , N , ... ) VariadicResize( N + I , __VA_ARGS__ ); FOR( VARIABLE_FOR_SET_A , 0 , N ){ VariadicSet( cin , VARIABLE_FOR_SET_A + I , __VA_ARGS__ ); } #define CIN_A( LL , I , N , ... ) VE __VA_ARGS__; SET_A( I , N , __VA_ARGS__ ) #define CIN_AA( LL , I0 , N0 , I1 , N1 , VAR ) VE> VAR( N0 + I0 ); FOR( VARIABLE_FOR_CIN_AA , 0 , N0 ){ SET_A( I1 , N1 , VAR[VARIABLE_FOR_CIN_AA + I0] ); } #define FINISH_MAIN SET_ASSERT( test_case_num , 1 , test_case_num_bound ); } REPEAT( test_case_num ){ Solve(); } CHECK_REDUNDANT_INPUT; } #endif #include using namespace std; #define START_MAIN int main(){ ios_base::sync_with_stdio( false ); cin.tie( nullptr ); SIGNAL; #define REPEAT_MAIN( BOUND ) START_MAIN; CEXPR( int , test_case_num_bound , BOUND ); int test_case_num = 1; if constexpr( test_case_num_bound > 1 ){ CERR( "テストケースの個数を入力してください。" ); FINISH_MAIN; #define START_WATCH chrono::system_clock::time_point watch = chrono::system_clock::now(); double loop_average_time = 0.0 , loop_start_time = loop_average_time , current_time = loop_start_time; int loop_count = current_time; assert( loop_count == 0 ) #define CURRENT_TIME ( current_time = static_cast( chrono::duration_cast( chrono::system_clock::now() - watch ).count() / 1000.0 ) ) #define CHECK_WATCH( TL_MS ) ( CURRENT_TIME , loop_count == 0 ? loop_start_time = current_time : loop_average_time = ( current_time - loop_start_time ) / loop_count , ++loop_count , current_time < TL_MS - loop_average_time * 2 - 100.0 ) #define CEXPR( LL , BOUND , VALUE ) CE LL BOUND = VALUE #define SET_ASSERT( A , MIN , MAX ) SET( A ); ASSERT( A , MIN , MAX ) #define SET_A_ASSERT( I , N , A , MIN , MAX ) FOR( VARIABLE_FOR_SET_A , 0 , N ){ SET_ASSERT( A[VARIABLE_FOR_SET_A + I] , MIN , MAX ); } #define SET_AA_ASSERT( I0 , N0 , I1 , N1 , A , MIN , MAX ) FOR( VARIABLE_FOR_SET_AA0 , 0 , N0 ){ FOR( VARIABLE_FOR_SET_AA1 , 0 , N1 ){ SET_ASSERT( A[VARIABLE_FOR_SET_AA0 + I0][VARIABLE_FOR_SET_AA1 + I1] , MIN , MAX ); } } #define CIN_ASSERT( A , MIN , MAX ) decldecay_t( MAX ) A; SET_ASSERT( A , MIN , MAX ) #define CIN_A_ASSERT( I , N , A , MIN , MAX ) vector A( N + I ); SET_A_ASSERT( I , N , A , MIN , MAX ) #define CIN_AA_ASSERT( I0 , N0 , I1 , N1 , A , MIN , MAX ) vector A( N0 + I0 , vector( N1 + I1 ) ); SET_AA_ASSERT( I0 , N0 , I1 , N1 , A , MIN , MAX ) #define PR1( A1 , ... ) A1 #define PR2( A1 , A2 , ... ) A2 #define PR3( A1 , A2 , A3 , ... ) A3 #define FOR_( VAR , INITIAL , FINAL , UPPER , COMP , INCR ) for( decldecay_t( UPPER ) VAR = INITIAL ; VAR COMP ( FINAL ) ; VAR INCR ) #define FOR( VAR , INITIAL , ... ) FOR_( VAR , INITIAL , PR1( __VA_ARGS__ ) , PR1( __VA_ARGS__ ) , < , PR3( __VA_ARGS__ , += PR2( __VA_ARGS__ , ? ) , ++ ) ) #define FOREQ( VAR , INITIAL , ... ) FOR_( VAR , INITIAL , PR1( __VA_ARGS__ ) , PR1( __VA_ARGS__ ) , <= , PR3( __VA_ARGS__ , += PR2( __VA_ARGS__ , ? ) , ++ ) ) #define FOREQINV( VAR , INITIAL , ... ) FOR_( VAR , INITIAL , PR1( __VA_ARGS__ ) , INITIAL , + 1 > , PR3( __VA_ARGS__ , -= PR2( __VA_ARGS__ , ? ) , -- ) ) #define ITR( ARRAY ) auto begin_ ## ARRAY = ARRAY .BE() , itr_ ## ARRAY = begin_ ## ARRAY , end_ ## ARRAY = ARRAY .EN() #define FOR_ITR( ARRAY ) for( ITR( ARRAY ) , itr = itr_ ## ARRAY ; itr_ ## ARRAY != end_ ## ARRAY ; itr_ ## ARRAY ++ , itr++ ) #define RUN( ARRAY , ... ) for( auto&& __VA_ARGS__ : ARRAY ) #define REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT , 0 , HOW_MANY_TIMES ) #define SET_PRECISION( DECIMAL_DIGITS ) cout << fixed << setprecision( DECIMAL_DIGITS ); cerr << fixed << setprecision( DECIMAL_DIGITS ) #define COUT( ... ) VariadicCout( cout , __VA_ARGS__ ) << ENDL #define COUTNS( ... ) VariadicCoutNonSep( cout , __VA_ARGS__ ) #define COUT_A( I , N , A ) CoutArray( cout , I , N , A ) << ENDL #define DERR( ... ) #define DERRNS( ... ) #define DERR_A( I , N , A ) #define WHAT( ... ) #define RETURN( ... ) COUT( __VA_ARGS__ ); return // 型のエイリアス #define decldecay_t( VAR ) decay_t template using ret_t = decltype( declval()( declval()... ) ); template using inner_t = typename T::type; using uint = unsigned int; using ll = long long; using ull = unsigned long long; using ld = long double; using lld = __float128; using path = pair; /* VVV 常設ライブラリの非圧縮版は以下に挿入する。*/ // BinarySearch constexpr bool reactive = #ifdef REACTIVE true; #else false; #endif // EXPRESSIONがANSWERの広義単調関数の時、EXPRESSION >= CONST_TARGETの整数解を格納。 #define BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , DESIRED_INEQUALITY , CONST_TARGET , INEQUALITY_FOR_CHECK , UPDATE_U , UPDATE_L , UPDATE_ANSWER , EXTERNAL ) \ static_assert( ! is_same::value && ! is_same::value ); \ ll ANSWER = MINIMUM; \ { \ ll ANSWER ## _L = MINIMUM; \ ll ANSWER ## _R = MAXIMUM; \ ANSWER = UPDATE_ANSWER; \ ll EXPRESSION_BS; \ const ll CONST_TARGET_BS = ( CONST_TARGET ); \ ll DIFFERENCE_BS; \ while( ANSWER ## _L < ANSWER ## _R ){ \ DIFFERENCE_BS = ( EXPRESSION_BS = ( EXPRESSION ) ) - CONST_TARGET_BS; \ if( DIFFERENCE_BS INEQUALITY_FOR_CHECK 0 ){ \ ANSWER ## _R = UPDATE_U; \ } else { \ ANSWER ## _L = UPDATE_L; \ } \ ANSWER = UPDATE_ANSWER; \ } \ if( ANSWER ## _L > ANSWER ## _R || !( reactive || ( EXPRESSION ) DESIRED_INEQUALITY CONST_TARGET_BS ) ){ \ ANSWER = EXTERNAL; \ } \ } \ // 単調増加の時にEXPRESSION >= CONST_TARGETの最小解を格納。 #define MIN_GEQ( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , CONST_TARGET ) BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , >= , CONST_TARGET , >= , ANSWER , ANSWER + 1 , Mid( ANSWER ## _L , ANSWER ## _R ) , ( MAXIMUM ) + 1 ) // 単調増加の時にEXPRESSION <= CONST_TARGETの最大解を格納。 #define MAX_LEQ( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , CONST_TARGET ) BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , <= , CONST_TARGET , > , ANSWER - 1 , ANSWER , Mid( ANSWER ## _L + 1 , ANSWER ## _R ) , ( MINIMUM ) - 1 ) // 単調減少の時にEXPRESSION >= CONST_TARGETの最大解を格納。 #define MAX_GEQ( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , CONST_TARGET ) BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , >= , CONST_TARGET , < , ANSWER - 1 , ANSWER , Mid( ANSWER ## _L + 1 , ANSWER ## _R ) , ( MINIMUM ) - 1 ) // 単調減少の時にEXPRESSION <= CONST_TARGETの最小解を格納。 #define MIN_LEQ( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , CONST_TARGET ) BS( ANSWER , MINIMUM , MAXIMUM , EXPRESSION , <= , CONST_TARGET , <= , ANSWER , ANSWER + 1 , Mid( ANSWER ## _L , ANSWER ## _R ) , ( MAXIMUM ) + 1 ) template inline constexpr INT Mid( const INT& l , const INT& r ) { return l + ( ( r - l ) >> 1 ); } // Random ll GetRand( const ll& Rand_min , const ll& Rand_max ) { assert( Rand_min <= Rand_max ); ll answer = time( NULL ); return answer * rand() % ( Rand_max + 1 - Rand_min ) + Rand_min; } // Set #define DC_OF_HASH( ... ) DECLARATION_OF_HASH( __VA_ARGS__ ) #define DECLARATION_OF_HASH( ... ) \ struct hash<__VA_ARGS__> \ { \ \ inline size_t operator()( const __VA_ARGS__& n ) const; \ \ }; \ #define DEFINITION_OF_POP_FOR_SET( SET ) \ template inline T pop_max( SET& S ) { assert( !S.empty() ); auto itr = --S.end(); T answer = *itr; S.erase( itr ); return answer; } \ template inline T pop_min( SET& S ) { assert( !S.empty() ); auto itr = S.begin(); T answer = *itr; S.erase( itr ); return answer; } \ template inline SET& operator<<=( SET& S , T t ) { S.insert( move( t ) ); return S; } \ template inline SET& operator<<=( SET& S , U&& u ) { S.insert( T{ forward( u ) } ); return S; } \ template inline SET& operator>>=( SET& S , const T& t ) { auto itr = S.lower_bound( t ); assert( itr != S.end() && *itr == t ); S.erase( itr ); return S; } \ template inline SET& operator>>=( SET& S , const U& u ) { return S >>= T{ u }; } \ template inline const T& Get( const SET& S , int i ) { auto begin = S.begin() , end = S.end(); auto& itr = i < 0 ? ( ++i , --end ) : begin; while( i > 0 && itr != end ){ --i; ++itr; } while( i < 0 && itr != begin ){ ++i; --itr; } assert( i == 0 ); return *itr; } \ #define DEFINITION_OF_UNION_FOR_SET( SET ) \ template inline SET& operator|=( SET& S0 , SET S1 ) { S0.merge( move( S1 ) ); return S0; } \ template inline SET operator|( SET S0 , SET S1 ) { return move( S0.size() < S1.size() ? S1 |= move( S0 ) : S0 |= move( S1 ) ); } \ class is_ordered { private: is_ordered() = delete; template static constexpr auto Check( const T& t ) -> decltype( t < t , true_type() ); static constexpr false_type Check( ... ); public: template static constexpr const bool value = is_same_v< decltype( Check( declval() ) ) , true_type >; }; template using Set = conditional_t>,unordered_set,conditional_t,set,void>>; template inline typename SET::const_iterator MaximumLeq( const SET& S , const T& t ) { auto itr = S.upper_bound( t ); return itr == S.begin() ? S.end() : --itr; } template inline typename SET::const_iterator MaximumLt( const SET& S , const T& t ) { auto itr = S.lower_bound( t ); return itr == S.begin() ? S.end() : --itr; } template inline typename SET::const_iterator MinimumGeq( const SET& S , const T& t ) { return S.lower_bound( t ); } template inline typename SET::const_iterator MinimumGt( const SET& S , const T& t ) { return S.upper_bound( t ); } template inline void EraseBack( SET& S , ITERATOR& itr ) { itr = S.erase( itr ); } template inline void EraseFront( SET& S , ITERATOR& itr ) { itr = S.erase( itr ); itr == S.begin() ? itr = S.end() : --itr; } template