// 3014用に書いていたのでぐちゃぐちゃ #include #include #include #include #include #include #include #include #include #include using namespace std; template ostream& operator << (ostream& os, vector vec){ for(int i=0; i #include /* case: 1000000000000000003 123456789987654321 */ class solver{ const long long p,b; const long long _p_, _b_; vector<__int128> v; vector<__int128> w; vector pos_shuffled; mt19937 mt; string s,t; int seed; static constexpr int len = 100; static constexpr int len__ = 100; bool solve_vec(){ vector c(len, 0); __int128 val = 0; __int128 hash = 0; bool ok = false; long long unko_seed = mt(); mt19937 my_mt(unko_seed); uniform_int_distribution pos(0, len__-1); uniform_int_distribution alf(0, 25); map memo; for(int i=0; isecond){ ok = true; my_mt = mt19937(unko_seed); //cerr << (long long) val << " " << (long long)hash << endl; vector d(len, 0); hash = 0; val = 0; for(int i=0; isecond || val != itr->first){ int at = pos_shuffled[pos(my_mt)]; int ch = alf(my_mt); val = (val + ((ch - d[at])*v[at])%p + p) % p; hash = (hash + ((ch - d[at])*w[at])%_p_ + _p_) % _p_; d[at] = ch; } //cerr << (long long) val << " " << (long long)hash << endl; for(int i=0; i> b >> p; solver x(p,b); x.unko(); return 0; }