Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int mod = 1e9 + 7;
- int p[100100];
- string gen_str() {
- string s;
- forn(i, 0, 20) {
- s += 'a' + rnd() % 26;
- }
- return s;
- }
- int get_hash(string s, int start) {
- int h = 0;
- forn(i, 0, sz(s)) {
- h = (h * 1ll * p[1] + s[i] - 'a' + 1) % mod;
- }
- h = h * 1ll * p[start] % mod;
- return h;
- }
- void solve(){
- int P, h;
- cin >> P >> h;
- forn1(i, 0, 100000) {
- p[i] = (i == 0 ? 1 : p[i - 1] * 1ll * P % mod);
- }
- unordered_map<int, string> st;
- forn(i, 0, 1e5) {
- string a = gen_str();
- st[get_hash(a, 20)] = a;
- }
- forn(i, 0, 1e5) {
- string a = gen_str();
- int hash = get_hash(a, 0);
- if (st.contains((h - hash + mod) % mod)) {
- cout << st[(h - hash + mod) % mod] << a << endl;
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement