#include using namespace std; uint64_t get_hash(const string &s, uint64_t a, uint64_t b) { uint64_t r = 0; for (int i = 0; i < s.size(); i++) { r = (r * a + s[i]) % b; } return r; } int main() { uint64_t a, b; cin >> a >> b; if (b == 1) { cout << "ab" << endl; cout << "ba" << endl; cerr << get_hash("ab", a, b) << endl; cerr << get_hash("ba", a, b) << endl; return 0; } int l = -1, r = -1; { int puni[b]; fill(puni, puni + b, -1); uint64_t muni = 1; for (int i = 0; i < 1000000; i++, (muni *= a) %= b) { if (0 <= puni[muni]) { l = puni[muni]; r = i; break; } puni[muni] = i; } } assert(0 <= l && l < r); string s(r + 1, ' '); { random_device rnd; for (auto &c : s) { c = 'a' + rnd() % 26; } } assert(0 <= s.size() && s.size() <= 1000000); cout << s << endl; cerr << get_hash(s, a, b) << endl; swap(s[s.size() - l - 1], s[0]); cout << s << endl; cerr << get_hash(s, a, b) << endl; return 0; }