Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.15 KB | None | 0 0
  1. #include <algorithm>
  2. #include <cstdio>
  3. #include <iostream>
  4. #include <iomanip>
  5. #include <vector>
  6. #include <map>
  7. #include <set>
  8. #include <cmath>
  9. #include <cstdlib>
  10. #include <ctime>
  11. #include <cstring>
  12. #include <string>
  13. #include <sstream>
  14. #include <queue>
  15. #include <bitset>
  16. #include <fstream>
  17. #include <stack>
  18. #include <deque>
  19. #include <utility>
  20. #include <numeric>
  21.  
  22. using namespace std;
  23. typedef long long ll;
  24. typedef pair <int, int> pii;
  25. const int N = 50;
  26. const int LIM = 5e5;
  27.  
  28. string s[N];
  29. bool used[LIM];
  30.  
  31. int main() {
  32.     freopen("input.txt", "r", stdin);
  33.     ios_base::sync_with_stdio(false);
  34.     int n;
  35.     cin >> n;
  36.     cout << 2 << "\n";
  37.     cout.flush();
  38.     cin >> s[1];
  39.     if (s[1] == "OK") return 0;
  40.     for (int i = 2; i <= 41; i++) {
  41.         cout << 2 << "\n";
  42.         cout.flush();
  43.         cin >> s[i];
  44.     }
  45.     for (int i = 2; i <= n; i++) {
  46.         if (used[i]) continue;
  47.         for (ll f = 1LL * i * i; f <= n; f += i) used[f] = true;
  48.     }
  49.     for (int t = n; t >= 3; t--) {
  50.         if (used[t]) continue;
  51.         int l = 1, r = t - 1;
  52.         for (int i = 1; i <= 41; i++) {
  53.             int m = (l + r) / 2;
  54.             if (s[i] == ">") r = m; else l = m + 1;
  55.             if (l == r) break;
  56.         }
  57.         if (l >= t) continue;
  58.         int x0 = l, x = l, nom;
  59.         for (int i = 1; i <= 41; i++) if (s[i] == "<") {
  60.             nom = i + 1;
  61.             break;
  62.         }
  63.         else x *= 2;
  64.         l = 1, r = t - 1;
  65.         for (int i = nom; i <= 41; i++) {
  66.             int m = (l + r) / 2;
  67.             if (s[i] == ">") r = m; else l = m + 1;
  68.             if (l == r) break;
  69.         }
  70.         if (l >= t) continue;
  71.         int p = 2 * x - l;
  72.         if (p != t) continue;
  73.         bool ok = true;
  74.         for (int i = 1; i <= 41; i++) {
  75.             x = x0 * 2;
  76.             if (x >= p) x -= p;
  77.             if ((x > x0 && s[i] == "<") || (x < x0 && s[i] == ">")) {
  78.                 ok = false;
  79.                 break;
  80.             }
  81.             x0 = x;
  82.         }
  83.         if (!ok) continue;
  84.         cout << p << "\n";
  85.         cout.flush();
  86.         cin >> s[42];
  87.         break;
  88.     }
  89.     return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement