Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <cstdio>
- #include <iostream>
- #include <set>
- #include <string>
- #include <vector>
- using namespace std;
- typedef long long i64;
- set<int> ps;
- set<int> n_ps;
- string Gen() {
- string res;
- for (int i = 0; i < 100; i++) {
- res += (char)(rand() % 26 + 'a');
- }
- return res;
- }
- int GetHash(const string &s, int x, int p) {
- int xi = 1;
- int res = 0;
- for (int i = 0; i < s.size(); i++) {
- res = (res + (s[i] - 'a' + 1) * (i64)xi) % p;
- xi = ((i64)xi * x) % p;
- }
- return res;
- }
- int main() {
- string s;
- cin >> s;
- cout << "aa\n";
- cout.flush();
- int x;
- cin >> x;
- x--;
- i64 xi = x;
- int i = 1;
- while ((xi - 1) / (x - 1) < 2000000000) {
- xi *= x;
- i++;
- }
- cout << string(i, 'a') << "\n";
- cout.flush();
- int h;
- cin >> h;
- i64 pi = (xi - 1) / (x - 1) - h;
- for (int i = 300; i >= 1; i--) {
- if (pi % i != 0) {
- continue;
- }
- i64 tmp_p = pi / i;
- if (tmp_p < 1000000000 || tmp_p > 2000000000) {
- continue;
- }
- if ((xi - 1) / (x - 1) % tmp_p == h) {
- ps.insert(tmp_p);
- }
- }
- while (ps.size() > 1) {
- s = Gen();
- cout << s << "\n";
- cout.flush();
- cin >> h;
- n_ps.clear();
- for (set<int>::iterator it = ps.begin(); it != ps.end(); it++) {
- int p = *it;
- int curr_h = GetHash(s, x, p);
- if (h == curr_h) {
- n_ps.insert(p);
- }
- }
- ps = n_ps;
- }
- int p = *ps.begin();
- cout << "answer: " << x << " " << p << "\n";
- cout.flush();
- }
Advertisement
Add Comment
Please, Sign In to add comment