text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; long long a, b; int t; int go(long long b, long long a) { if (!a || !b) return 0; if (!go(a, b % a)) return 1; if (a % 2 == 1) return (((b / a) % 2) ^ 1); return (((b / a) % (a + 1) % 2) ^ 1); } int main() { cin.sync_with_stdio(0); cin >> t; while (t--) { cin >> a >> b; if (a > b) swap(a, b); if (go(b, a)) puts("First"); else puts("Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; int test; long long a, b; bool win(long long a, long long b) { if (b == 0) return false; if (!win(b, a % b)) return true; if (((a / b) % (b + 1)) & 1) return false; return true; } int main() { scanf("%d", &test); for (int i = 0; i < test; ++i) { scanf("%I64d %I64d", &a, &b); if (a < b) swap(a, b); if (win(a, b)) puts("First"); else puts("Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; bool solve(long long a, long long b) { if (a > b) { return solve(b, a); } if (a == 0) { return false; } bool next = solve(b % a, a); if (!next) { return true; } return (((b / a) % (a + 1)) % 2 == 0); long long c = (b / a); if ((a % 2 == 1) || (c / a < a)) { return (c % 2 == 0); } else { return (((b / a) % (a + 1)) % 2 == 0); } } inline void init() {} int main() { init(); bool prev = false; int T; while (cin >> T) { if (prev) { cout << endl; } prev = true; long long a, b; for (int i = 0; i < T; i++) { cin >> a >> b; cout << (solve(a, b) ? "First" : "Second") << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; long long inline read() { long long x = 0, f = 0; char ch = getchar(); while (ch < '0' || ch > '9') f ^= (ch == '-'), ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48), ch = getchar(); return f ? -x : x; } bool check(long long x, long long y) { if (x < y) swap(x, y); if (!y) return false; long long z = x / y; bool w = check(y, x % y); if (!w) return true; if (y & 1) return (z & 1) ^ 1; return z % (y + 1) & 1 ^ 1; } signed main() { long long t = read(); while (t--) { long long n = read(), m = read(); puts(check(n, m) ? "First" : "Second"); } }
#include <bits/stdc++.h> using namespace std; const double EPS = (1e-10); bool EQ(double a, double b) { return abs((a) - (b)) < EPS; } void fast_stream() { std::ios_base::sync_with_stdio(0); } bool dfs(long long x, long long y) { if (!(x && y)) return false; if (x > y) swap(x, y); return !dfs(y % x, x) | !(((y / x) % (x + 1)) % 2); } int t; void solve() { cin >> t; while (t--) { long long a, b; cin >> a >> b; bool res = dfs(a, b); if (res) cout << "First" << endl; else cout << "Second" << endl; } } int main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int MOD = 1e9 + 7; const int maxn = 1e6 + 10; const double eps = 1e-9; int t; bool dfs(long long a, long long b) { if (a > b) swap(a, b); if (!a) return false; if (b % a == 0) return true; int ok = 1; if (!dfs(b % a, a)) return true; if ((b / a) % (a + 1) % 2 == 0) return true; return false; } int main() { ios_base::sync_with_stdio(0); scanf("%d", &t); while (t--) { long long a, b; scanf("%I64d%I64d\n", &a, &b); int flag = dfs(a, b); if (flag) printf("First\n"); else printf("Second\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; int t; long long a, b; int res(long long x, long long y) { assert(x <= y); if (x == 0) return 0; if (!res(y % x, x)) { return 1; } assert(x > 1); long long z = y / x, sum = 0; if (x & 1) return 1 - z % 2; else return 1 - (z % (x + 1)) % 2; } int main() { scanf("%d", &t); while (t--) { scanf("%lld %lld", &a, &b); if (a > b) swap(a, b); printf("%s\n", res(a, b) ? "First" : "Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 100010; const int INF = 0x3f3f3f3f; const int iinf = 1 << 30; const long long linf = 2e18; const int mod = 1000000007; const double eps = 1e-7; void douout(double x) { printf("%lf\n", x + 0.0000000001); } template <class T> void print(T a) { cout << a << endl; exit(0); } template <class T> void chmin(T &a, T b) { if (a > b) a = b; } template <class T> void chmax(T &a, T b) { if (a < b) a = b; } void add(int &a, int b) { a = a + b < mod ? a + b : a + b - mod; } void sub(int &a, int b) { a = (a - b + mod) % mod; } void mul(int &a, int b) { a = (long long)a * b % mod; } int addv(int a, int b) { return (a += b) >= mod ? a -= mod : a; } int subv(int a, int b) { return (a -= b) < 0 ? a += mod : a; } int mulv(int a, int b) { return (long long)a * b % mod; } int read() { int f = 1, x = 0; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int pw(int a, int b) { int s = 1; for (; b; b >>= 1, a = (long long)a * a % mod) if (b & 1) s = (long long)s * a % mod; return s; } long long a, b; int f(long long a, long long b) { if (a == 0 || b == 0) return 0; if (a > b) return f(b, a); if (!f(b % a, a)) return 1; long long t = b / a; return !(t % (a + 1) % 2); } signed main() { int T; scanf("%d", &T); while (T--) { scanf("%lld%lld", &a, &b); puts(f(a, b) ? "First" : "Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; bool win(long long A, long long B) { if (A == 0 || B == 0) return false; if (A > B) swap(A, B); if (!win(A, B % A)) return true; long long N = B / A; long long MOD = A + 1; return ((N % MOD) % 2 == 0); } int main(void) { int T, t; long long A, B; cin >> T; for ((t) = 0; (t) < (int)(T); (t)++) { cin >> A >> B; bool ans = win(A, B); cout << (ans ? "First" : "Second") << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e2 + 7; const int INF = 1e9 + 7; const int MOD = 1e9 + 7; const double Pi = acos(-1.0); const double EPS = 1e-8; bool dfs(long long a, long long b) { if (a == 0 || b == 0) return false; if (!dfs(b % a, a)) return true; long long k = b / a; return k % (a + 1) % 2 == 0; } int main() { int T; cin >> T; for (int cas = (0); cas < (T); ++cas) { long long a, b; cin >> a >> b; if (a > b) swap(a, b); if (dfs(a, b)) cout << "First" << endl; else cout << "Second" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; char s[2][10] = {"First", "Second"}; int f(long long a, long long b) { if (a < b) swap(a, b); if (b == 0) return 1; if (b % 2) { if (a / b % (b + 1) % 2) return 1 - f(a % b, b); else return 0; } else if ((a / b) % (b + 1) % 2) return 1 - f(a % b, b); else return 0; } long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } int rc[1234][1234]; int bl(long long a, long long b) { if (a < b) swap(a, b); if (rc[a][b] >= 0) return rc[a][b]; if (b == 0) return rc[a][b] = 1; if (a % b == 0) return rc[a][b] = 0; int flag = bl(b, a % b); for (long long x = b; !flag && a >= x; x *= b) { flag |= bl(a - x, b); if (a / x < b) break; } return rc[a][b] = 1 - flag; } int main(int argc, char *argv[]) { int t; scanf("%d", &t); do { memset(rc, -1, sizeof(rc)); } while (0); for (int i = 0; i < t; i++) { long long a, b; cin >> a >> b; if (a == b && b == 0) { printf("%s\n", s[1]); continue; } printf("%s\n", s[f(a, b)]); } return EXIT_SUCCESS; }
#include <bits/stdc++.h> using namespace std; int find(long long u, long long v) { if (u > v) swap(u, v); if (u == 0) return 0; if (!find(u, v % u)) return 1; long long d = v / u; return !(d % (u + 1) % 2); } int main() { long long tt, n, m; cin >> tt; while (tt--) { scanf("%lld%lld", &n, &m); puts((find(n, m)) ? "First" : "Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; const int block_size = 320; const long long mod = 1e9 + 7; const long long inf = 1e9 + 7; const long double eps = 1e-9; const double PI = atan(1) * 4; template <typename T> inline int sign(const T &a) { if (a < 0) return -1; if (a > 0) return 1; return 0; } template <typename T, typename S> inline bool upmin(T &a, const S &b) { return a > b ? a = b, 1 : 0; } template <typename T, typename S> inline bool upmax(T &a, const S &b) { return a < b ? a = b, 1 : 0; } template <typename T> inline void in(T &x) { x = 0; T f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); } x *= f; } long long twop(int x) { return 1LL << x; } template <typename A, typename B> inline void in(A &x, B &y) { in(x); in(y); } template <typename A, typename B, typename C> inline void in(A &x, B &y, C &z) { in(x); in(y); in(z); } template <typename A, typename B, typename C, typename D> inline void in(A &x, B &y, C &z, D &d) { in(x); in(y); in(z); in(d); } bool win(long long a, long long b) { if (a < b) swap(a, b); if (b == 0) return false; bool res = win(b, a % b); if (res == false) return true; else { a /= b; if (b % 2 == 1) { return a % 2 == 0; } else { a %= b + 1; if (a % 2 == 0) return true; return false; } } } int main() { int n; in(n); while (n--) { long long a, b; in(a, b); puts(win(a, b) ? "First" : "Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; int t; long long at, bt; bool solve(long long a, long long b) { if (a > b) swap(a, b); if (a == 0) return false; if (solve(b % a, a)) { b -= b % a; b /= a; if (a % 2 != 0) { return (b % 2) == 0; } else { b %= a + 1; return (b % 2) == 0; } } else return true; } int main() { scanf("%d", &t); while (t--) { scanf("%I64d %I64d", &at, &bt); if (solve(at, bt)) printf("First\n"); else printf("Second\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; bool ganador(long long int a, long long int b) { assert(a <= b); if (a == 0) return false; long long int d = b % a; bool rec = ganador(d, a); if (!rec) return true; assert(a != 1); long long int diff = b / a - 1; diff %= (a + 1); return diff % 2 == 1 || diff == a; } int main() { cin.tie(0); ios::sync_with_stdio(0); int n; cin >> n; while (n--) { long long int a, b; cin >> a >> b; if (ganador(min(a, b), max(a, b))) cout << "First\n"; else cout << "Second\n"; } }
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long powmod(long long a, long long b) { long long res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } int t; long long a, b; bool winp(long long a, long long b) { if (b == 0) return 0; if (a % b == 0) return 1; if (!winp(b, a % b)) return 1; return 1 - a / b % (b + 1) % 2; } int main() { for (scanf("%d", &t); t; t--) { cin >> a >> b; if (a < b) swap(a, b); if (winp(a, b)) puts("First"); else puts("Second"); } }
#include <bits/stdc++.h> bool win(long long a, long long b) { if (a == 0) return false; if (!win(b % a, a)) return true; long long r = (b / a - 1) % (a + 1) + 1; return r == a + 1 || r % 2 == 0; } int main() { int t; scanf("%d", &t); while (t--) { long long a, b; scanf("%I64d%I64d", &a, &b); if (a > b) a ^= b ^= a ^= b; puts(win(a, b) ? "First" : "Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; int dfs(long long a, long long b) { if (a > b) swap(a, b); if (a == 0) return 2; if (dfs(a, b % a) == 2) return 1; if ((b / a) % (a + 1) % 2 == 0) return 1; return 2; } int main() { int T; scanf("%d", &T); while (T--) { long long a, b; scanf("%I64d%I64d", &a, &b); if (dfs(a, b) == 1) printf("First\n"); else printf("Second\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; bool do_i_win(long long int a, long long int b) { if (a == 0) return 0; if (a == 1) return 1; if (b % a == 0) return 1; bool next_turn = do_i_win(b % a, a); if (next_turn == 0) return 1; else { long long int x = (b / a) % (a + 1); if (x & 0x1) return 0; else return 1; } } int main(void) { int n; long long int a, b; bool result; cin >> n; for (int i = 0; i < n; i++) { cin >> a >> b; if (a < b) result = do_i_win(a, b); else result = do_i_win(b, a); if (result == 1) cout << "First" << endl; else cout << "Second" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int T; long long a, b; bool check(long long x, long long y) { if (x == 0 || y == 0) return false; if (x < y) swap(x, y); if (!check(y, x % y)) return true; return x / y % (y + 1) % 2 == 0; } int main() { scanf("%d", &T); while (T--) { scanf("%I64d%I64d", &a, &b); printf("%s\n", check(a, b) ? "First" : "Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; int dfs(long long a, long long b) { if (!a) return 1; if (dfs(b % a, a)) return 0; if (a & 1) return (b / a) & 1; return (b / a) % (a + 1) & 1; } int main() { int t; scanf("%d", &t); while (t--) { long long a, b; scanf("%lld%lld", &a, &b); if (a > b) swap(a, b); if (dfs(a, b)) puts("Second"); else puts("First"); } return 0; }
#include <bits/stdc++.h> using namespace std; bool g(long long a, long long b) { if (b == 0) return 0; if (g(b, a % b) == 0) return 1; long long q = a / b; if (b % 2) return q % 2 ? 0 : 1; q %= 2 * (b + 1); if (q > b) q = 2 * b + 1 - q; return q % 2 ? 0 : 1; } long long T, a, b; int main() { ios_base::sync_with_stdio(0); cin >> T; while (T--) { cin >> a >> b; if (a < b) swap(a, b); cout << (g(a, b) ? "First" : "Second") << endl; } }
#include <bits/stdc++.h> using namespace std; bool win(long long a, long long b) { if (a < b) swap(a, b); if (!b) return (false); if (!win(b, a % b)) return (true); long long p = a / b; return (p % (b + 1) % 2 == 0); } int main() { int T; scanf("%d", &T); while (T--) { long long a, b; scanf("%I64d%I64d", &a, &b); printf("%s\n", win(a, b) ? "First" : "Second"); } return (0); }
#include <bits/stdc++.h> using namespace std; inline bool dfs(long long a, long long b) { if (a == 0 || b == 0) return 0; if (a > b) swap(a, b); long long z = b % a; if (!dfs(a, z)) return 1; if ((b / a) % (a + 1) % 2 == 0) return 1; else return 0; } signed main() { ios::sync_with_stdio(false); long long cases; cin >> cases; for (long long i = 1; i <= cases; i++) { long long x, y; cin >> x >> y; if (dfs(x, y)) { cout << "First" << endl; } else cout << "Second" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; bool f(long long a, long long b) { if (a > b) return f(b, a); if (a == 0) return false; bool res = f(b % a, a) == false; if (res) return res; long long q = b / a - 1; if (a % 2 == 1) res |= q % 2 == 1; else { if ((q % (a + 1)) == a) res |= true; else res |= (q % (a + 1)) % 2; } return res; } void solve() { int t; cin >> t; while (t--) { long long a, b; cin >> a >> b; if (f(a, b)) cout << "First" << endl; else cout << "Second" << endl; } } int main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigmod(T p, T e, T M) { if (e == 0) return 1; if (e % 2 == 0) { T t = bigmod(p, e / 2, M); return (t * t) % M; } return (bigmod(p, e - 1, M) * p) % M; } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } template <class T> inline T modinverse(T a, T M) { return bigmod(a, M - 2, M); } template <class T> inline T multimod(T a, T b, T m) { T ans = 0ll; a %= m, b %= m; while (b) { if (b & 1ll) ans = m - ans > a ? (ans + a) : (ans + a - m); b >>= 1ll; a = (m - a) > a ? a + a : a + a - m; } return (T)ans; } long long dp[102][2688]; char str[102]; long long solve(long long a, long long b) { if (a < b) swap(a, b); if (a == 0ll || b == 0ll) return false; if (!solve(b, a % b)) return true; long long x = a / b; return (x % (b + 1) % 2 == 0); } int main() { int i, j, x, y, k; int u, v, m, q, t, n, w; memset(dp, -1ll, sizeof dp); scanf("%d", &t); while (t--) { long long a, b; cin >> a >> b; if (solve(a, b)) cout << "First" << endl; else cout << "Second" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> T abs(T a) { return a < 0 ? -a : a; } template <typename T> T sqr(T a) { return a * a; } const int INF = (int)1e9; const long double EPS = 1e-9; const long double PI = 3.1415926535897932384626433832795; const int N = 2000; long long a, b; int gcd(long long a, long long b) { if (a > b) swap(a, b); if (a == 0) return 0; int cur = 1 - gcd(b % a, a); if (cur) return 1; else { long long x = b / a; long long n = a; if (n & 1) return 1 - (x & 1); long long pr = x % (n + 1); return 1 - (pr & 1); } } int main() { int tests; cin >> tests; for (int test = 0; test < int(tests); ++test) { cin >> a >> b; int ans = gcd(a, b); puts(ans ? "First" : "Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; int calc(long long a, long long b) { if (b > a) swap(a, b); if (!b) return 0; if (!calc(b, a % b)) return 1; long long c = a / b; return !((c % (b + 1)) % 2); } int main() { long long a, b, t; cin >> t; while (t--) { cin >> a >> b; if (calc(a, b)) puts("First"); else puts("Second"); } }
#include <bits/stdc++.h> using namespace std; long long dfs(long long x, long long y) { if (x < y) { swap(x, y); } if (!y) { return 0; } if (dfs(x % y, y) == 0) { return 1; } else { return ((x / y) % (y + 1) + 1) % 2; } } int32_t main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); long long t; cin >> t; while (t--) { long long x, y; cin >> x >> y; cout << (dfs(x, y) ? "First\n" : "Second\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; int get1(long long bx, long long b) { long long x = bx / b; if (b % 2) { return (x + 1) % 2; } x %= (b + 1); if (x == 0) return 2; return (x + 1) % 2; } vector<long long> A; vector<long long> B; int pre[200]; int n; int get(int pos) { if (pos == (n - 1)) return 0; int ret = get(pos + 1); if (pre[pos]) return 1; if (ret == 1) { return 0; } else { return 1; } } int main() { int i, j; long long b, x, a, c; int T; scanf("%d", &T); while (T--) { A.clear(); B.clear(); scanf("%I64d %I64d", &a, &b); if (a < b) swap(a, b); if (a == 0 || b == 0) { printf("Second\n"); continue; } A.push_back(a); B.push_back(b); while (a && b) { c = a % b; a = b; b = c; A.push_back(a); B.push_back(b); } n = A.size(); for (i = 0; i < n - 1; i++) { pre[i] = get1((A[i] / B[i]) * B[i], B[i]); } int ans = get(0); if (ans) printf("First\n"); else printf("Second\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; long long a, b, t, z; bool dfs(long long x, long long y) { if (x < y) swap(x, y); if (!y) return 0; if (!dfs(y, x % y)) return 1; z = x / y; if (y & 1) return (z & 1) ^ 1; return z % (y + 1) & 1 ^ 1; } signed main() { scanf("%lld", &t); while (t--) { scanf("%lld%lld", &a, &b); if (dfs(a, b)) printf("First\n"); else printf("Second\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 5, inf = 0x3f3f3f3f, mod = 1e9 + 7; int t; long long a, b; bool check(long long a, long long b) { if (a > b) swap(a, b); if (a == 0) return false; if (!check(a, b % a)) return true; long long k = b / a; return k % (a + 1) % 2 == 0; } int main() { scanf("%d", &t); while (t--) { scanf("%I64d%I64d", &a, &b); puts(check(a, b) ? "First" : "Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; bool win(long long a, long long b) { if (a > b) swap(a, b); if (a == 0) return false; bool type = win(b % a, a); if (!type) return true; b /= a; if (a % 2 == 1) { if (b % 2 == 0) return true; return false; } else { if ((b % (a + 1)) % 2 == 0) return true; return false; } } int main() { int N; cin >> N; while (N--) { long long a, b; cin >> a >> b; if (win(a, b)) cout << "First\n"; else cout << "Second\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const int M = 100 + 10; int GCD(long long int a, long long int b) { if (b == 0) { return 0; } int res = GCD(b, a % b); if (res == 0) { return 1; } else { long long int k = a / b; if (b & 1) { int ans = 1 - k % 2; return ans; } else { if (k % (b + 1) == 0) { return 1; } else { int ans = 1 - k % (b + 1) % 2; return ans; } } } } int main() { time_t t_start, t_end; t_start = clock(); int t; cin >> t; for (int i = 0; i < t; i++) { long long int a, b; cin >> a >> b; if (b > a) { long long int tmp = a; a = b; b = tmp; } int res = GCD(a, b); string ans = (res == 1 ? "First" : "Second"); cout << ans << endl; } t_end = clock(); return 0; }
#include <bits/stdc++.h> using namespace std; bool dfs(long long a, long long b) { if (a == 0 || b == 0) return 0; return !dfs(b, a % b) || (a / b % (b + 1) % 2 == 0); } int main() { long long a, b; int t; scanf("%d", &t); while (t--) { scanf("%I64d%I64d", &a, &b); if (a < b) swap(a, b); if (dfs(a, b)) puts("First"); else puts("Second"); } }
#include <bits/stdc++.h> using namespace std; bool f(long long a, long long b) { if (a > b) swap(a, b); if (a == 0) return false; if (!f(b % a, a)) return true; return ((b / a) % (a + 1)) % 2 == 0; } int main() { long long a, b; int k, bit, t, i, j, s[2], odd, tot; cin >> tot; for (k = 1; k <= tot; ++k) { cin >> a >> b; if (f(a, b)) cout << "First\n"; else cout << "Second\n"; } }
#include <bits/stdc++.h> using namespace std; int t; long long a, b; void swap(long long &a, long long &b) { const long long t = a; a = b, b = t; } bool solve(long long a, long long b) { if (a > b) swap(a, b); if (!a) return false; long long x = b / a; bool f = solve(b % a, a); if (!f) return true; if (a & 1) return f ? (!(x & 1)) : (x & 1); else { x %= (a + 1); return f ? (!(x & 1)) : (x & 1); } } int main() { scanf("%d", &t); while (t--) { scanf("%lld%lld", &a, &b); puts(solve(a, b) ? "First" : "Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; bool win(long long a, long long b) { if (a < b) swap(a, b); if (!b) return 0; if (!win(b, a % b)) return 1; long long temp = (a / b) % (b + 1); if (temp & 1) return 0; return 1; } int main() { int T; long long x, y; cin >> T; while (T--) { cin >> x >> y; if (win(x, y)) puts("First"); else puts("Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0; int f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48); return x * f; } void print(long long x) { if (x < 0) x = -x, putchar('-'); if (x > 9) print(x / 10); putchar(x % 10 + '0'); } bool solve(long long a, long long b) { if (!a || !b) return false; long long k = (b / a - 1) % (a + 1); return (!solve(b % a, a)) | (k & 1) | (k == a); } int main() { int T = read(); while (T--) { long long a = read(), b = read(); if (a > b) swap(a, b); puts(solve(a, b) ? "First" : "Second"); } }
#include <bits/stdc++.h> using namespace std; long long T; bool Solve(long long A, long long B) { if (B == 0) return false; bool prev = Solve(B, A % B); if (!prev) return true; A = (A / B) - 1; if (B % 2 == 1) return (A % 2 == 1); return ((A % (B + 1)) % 2 == 1 || A % (B + 1) == B); } int main() { ios::sync_with_stdio(false); cin >> T; long long A, B; while (T--) { cin >> A >> B; bool IsWin = Solve(max(A, B), min(A, B)); if (IsWin) cout << "First" << endl; else cout << "Second" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; bool win(long long a, long long b) { if (a == 0) return false; if (!win(b % a, a)) return true; else return (b / a) % (a + 1) % 2 == 0; } int main() { int T; long long a, b; cin >> T; while (T--) { cin >> a >> b; if (a > b) swap(a, b); cout << (win(a, b) ? "First" : "Second") << endl; } }
#include <bits/stdc++.h> using namespace std; bool solve(long long a, long long b) { if (a > b) { swap(a, b); } if (a == 0) { return false; } long long md = b % a; b /= a; if (solve(md, a)) { if (b % (a + 1) == 0) { return true; } else { if ((b % (a + 1)) % 2) { return false; } else { return true; } } } else { if (b > 0) { return true; } else { return false; } } } int t; long long a, b; int main() { cin >> t; while (t--) { cin >> a >> b; if (a > b) { swap(a, b); } if (solve(a, b)) { cout << "First" << endl; } else { cout << "Second" << endl; } } }
#include <bits/stdc++.h> using namespace std; template <class T> inline void chkmin(T &a, T b) { if (a > b) a = b; } template <class T> inline void chkmax(T &a, T b) { if (a < b) a = b; } bool win(long long a, long long b) { if (a == 0 || b == 0) return false; if (a > b) swap(a, b); if (!win(a, b % a)) return true; return (b / a) % (a + 1) % 2 == 0; } int main() { int T; long long a, b; for (scanf("%d", &T); T--;) { scanf("%I64d%I64d", &a, &b); if (win(a, b)) puts("First"); else puts("Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; long long m[100010]; bool check(long long a, long long b) { if (a < b) swap(a, b); int gs = 0; m[gs++] = a; m[gs++] = b; while (b != 0) { m[gs++] = a % b; a = b; b = m[gs - 1]; } bool flag = false; for (int i = gs - 2; i > 0; i--) { if (m[i] % 2 == 1) { if ((m[i - 1] / m[i]) % 2 == 0) { flag = true; } else { flag = !flag; } } else { if (!flag) { flag = true; continue; } if (((m[i - 1] / m[i]) % (m[i] + 1)) % 2 == 0) flag = true; else flag = false; } } return flag; } int main() { int t; long long a, b; scanf("%d", &t); for (int i = 0; i < t; i++) { scanf("%I64d%I64d", &a, &b); if (check(a, b)) printf("First\n"); else printf("Second\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; inline int L(int i) { return i << 1; } inline int R(int i) { return (i << 1) | 1; } inline int B(int i) { return 1 << i; } inline int low_bit(int x) { return x & (-x); } long long cnt[1010], top; long long tmp, mul; bool must_win(long long a, long long b) { if (a == 0 || b == 0) return 0; if (a > b) tmp = a, a = b, b = tmp; if (must_win(b % a, a) == 0) return 1; tmp = b; tmp /= a; tmp %= a + 1; if (tmp & 1) return 0; return 1; } int main() { int t; long long a, b; cin >> t; while (t--) { cin >> a >> b; if (must_win(a, b)) puts("First"); else puts("Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; long long A[114], B[114]; int op[114]; int cnt; void PushIn(long long a, long long b) { ++cnt, A[cnt] = a, B[cnt] = b; if (b == 0) return void(); PushIn(b, a % b); } int main() { int T; cin >> T; while (T--) { long long a, b; cin >> a >> b; cnt = 0; PushIn(max(a, b), min(a, b)); op[cnt] = 0; for (register int i = cnt - 1; i; --i) if (op[i + 1] == 0) op[i] = 1; else { long long tim = A[i] / B[i]; if ((tim % (B[i] + 1)) & 1) op[i] = 0; else op[i] = 1; } if (op[1]) puts("First"); else puts("Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 5; const int MAXN = 100000007; const int MOD = 1e9 + 7; const double eps = 1e-8; const double PI = acos(-1.0); long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long getSG(long long x, long long y) { if (x == 0 || y == 0) return 0; long long a = min(x, y); long long b = max(x, y); if (getSG(b % a, a)) { b /= a; return !((b % (a + 1)) & 1); } return 1; } int main() { long long a, b; int T; scanf("%d", &T); while (T--) { scanf("%lld%lld", &a, &b); if (getSG(a, b) == 0) printf("Second\n"); else printf("First\n"); } }
#include <bits/stdc++.h> const int N = 100010; const int inf = 0x3f3f3f3f; using namespace std; bool gcd(long long a, long long b) { if (a < b) swap(a, b); if (b == 0) return 0; if (!gcd(b, a % b)) return 1; return a / b % (b + 1) % 2 == 0; } int main() { long long a, b; int ca; for (cin >> ca; ca--;) { cin >> a >> b; if (gcd(a, b)) puts("First"); else puts("Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; int tests; long long a, b; int win(long long a, long long b) { long long t; if (a > b) t = a, a = b, b = t; if (!a) return 0; if (!win(b % a, a)) return 1; if ((((b / a)) % (a + 1)) % 2) return 0; else return 1; } int main() { cin >> tests; for (int i = 1; i <= tests; i++) { cin >> a >> b; if (win(a, b)) cout << "First" << endl; else cout << "Second" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; bool func(long long a, long long b) { if (a > b) return func(b, a); if (a == 0) return false; if (!func(b % a, a)) return true; long long k = b / a; if (a % 2 == 1) return k % 2 == 0; long long m = k % (a + 1); return m % 2 == 0; } int main() { int t; long long a, b; cin >> t; while (t--) { cin >> a >> b; cout << (func(a, b) ? "First" : "Second") << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; bool is_Smaller_str(string str1, string str2) { long long n1 = str1.length(), n2 = str2.length(); if (n1 < n2) return true; if (n2 < n1) return false; for (int i = 0; i < n1; i++) if (str1[i] < str2[i]) return true; else if (str1[i] > str2[i]) return false; return false; } long long mod(long long a, long long b) { long long ans = a / b; ans *= b; ans = a - ans; return ans; } string find_Diff_str(string str1, string str2) { if (is_Smaller_str(str1, str2)) swap(str1, str2); string str = ""; long long n1 = str1.length(), n2 = str2.length(); reverse(str1.begin(), str1.end()); reverse(str2.begin(), str2.end()); long long carry = 0; for (long long i = 0; i < n2; i++) { long long sub = ((str1[i] - '0') - (str2[i] - '0') - carry); if (sub < 0) { sub = sub + 10; carry = 1; } else carry = 0; str.push_back(sub + '0'); } for (long long i = n2; i < n1; i++) { long long sub = ((str1[i] - '0') - carry); if (sub < 0) { sub = sub + 10; carry = 1; } else carry = 0; str.push_back(sub + '0'); } reverse(str.begin(), str.end()); return str; } string find_sum_str(string str1, string str2) { if (str1.length() > str2.length()) swap(str1, str2); string str = ""; int n1 = str1.length(), n2 = str2.length(); reverse(str1.begin(), str1.end()); reverse(str2.begin(), str2.end()); int carry = 0; for (int i = 0; i < n1; i++) { int sum = ((str1[i] - '0') + (str2[i] - '0') + carry); str.push_back(sum % 10 + '0'); carry = sum / 10; } for (int i = n1; i < n2; i++) { int sum = ((str2[i] - '0') + carry); str.push_back(sum % 10 + '0'); carry = sum / 10; } if (carry) str.push_back(carry + '0'); reverse(str.begin(), str.end()); return str; } void FAST() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } long long Rselect(vector<long long> v, long long i, long long l, long long r); long long partition(vector<long long> v, long long l, long long r); void scanc(vector<char>& v, long long n) { for (long long i = 0; i < n; i++) { char num; cin >> num; v.push_back(num); } } void scanP(vector<pair<long long, long long> >& v, long long n) { for (long long i = 0; i < n; i++) { long long num1, num2; cin >> num1 >> num2; pair<long long, long long> p = {num1, num2}; v.push_back(p); } } template <typename T> ostream& operator<<(ostream& stream, const vector<T>& vec) { for (auto& i : vec) { stream << i << ' '; } stream << '\n'; return stream; } template <class T> istream& operator>>(istream& stream, vector<T>& vec) { for (auto& i : vec) { stream >> i; } return stream; } void solve(); void scanN(vector<long long>& v, long long n) { for (long long i = 0; i < n; i++) { long long num; cin >> num; v.push_back(num); } } void scans(vector<string>& v, long long n) { for (long long i = 0; i < n; i++) { string s; cin >> s; v.push_back(s); } } long long modfactorial(long long n, long long p) { if (n >= p) return 0; long long result = 1; for (long long i = 1; i < n + 1; i++) { result = result * i; result = result % p; } return result; } long long MI(long long a, long long b, long long s0 = 1, long long s1 = 0) { long long k = b; if (b == 0) return s0; else { return MI(b, a % b, s1, s0 - s1 * (a / b)); } } long long choose(long long a, long long b, long long c = (long long)1e9 + 7) { if (a < b) return 0; long long x = modfactorial(a, c); long long y = modfactorial(b, c); long long z = modfactorial(a - b, c); long long y_ = MI(y, c, 1, 0); if (y_ < 0) y_ = y_ + c; long long z_ = MI(z, c, 1, 0); if (z_ < 0) z_ = z_ + c; long long mul = (x * y_) % c; mul = (mul * z_) % c; return mul; } void SOLT() { int test; cin >> test; while (test--) { solve(); } } long long modpow(long long n, long long p, long long k) { n = n % k; long long res = 1; while (p > 0) { if (p % 2 == 1) res = res * n % k; n = n * n % k; p = p / 2; } return res; } long long __pow(long long n, long long p) { long long res = 1; while (p > 0) { if (p % 2 == 1) res = res * n; n = n * n; p = p / 2; } return res; } long long str_mod_num(string b, long long c) { long long k = b.size(); vector<long long> mod(k + 1); mod[0] = 1; for (long long i = 1; i < k + 1; i++) { mod[i] = 10 * mod[i - 1]; mod[i] %= c; } long long rem = 0; for (long long i = k - 1; i > -1; i--) { long long num = b[i] - '0'; num *= mod[k - 1 - i]; num %= c; rem += num; rem %= c; } return rem; } long long str_pow_str_mod_num(string b, string n, long long c) { long long tr = n.size(); long long rem = str_mod_num(b, c); long long time_pass = n[0] - '0'; long long ans = modpow(rem, time_pass, c); for (long long i = 1; i < tr; i++) { time_pass = n[i] - '0'; ans = modpow(ans, 10, c); ans *= modpow(rem, time_pass, c); ans %= c; } return ans; } bool isPrime(long long a) { for (long long i = 2; i * i <= a; ++i) if (a % i == 0) return false; return true; } bool useflushdivisible(long long a) { cout << a << endl; fflush(stdout); char sl[10]; scanf("%s", sl); return sl[0] == 'y' || sl[0] == 'Y'; } long long phi(long long n) { long long result = n; for (long long i = 2; i * i <= n; i++) { if (n % i == 0) { while (n % i == 0) n = n / i; result = result - result / i; } } if (n > 1) result = result - result / n; return result; } bool cmp(pair<long long, long long> x, pair<long long, long long> y) { return x.first < y.first; } vector<long long> getfactors(long long n) { vector<long long> factors; for (long long i = 1; i < sqrt(n) + 1; i++) { if (n % i == 0) { factors.push_back(i); if (i != (n / i)) factors.push_back(n / i); } } return factors; } long long Binary_Search(vector<long long>& a, long long low, long long high, long long key) { if (high < low) return a[low - 1]; int mid = (high + low) / 2; if (key == a[mid]) return a[mid]; else if (key < a[mid]) return Binary_Search(a, low, mid - 1, key); return Binary_Search(a, mid + 1, high, key); } double area(long long x1, long long y1, long long x2, long long y2, long long x3, long long y3) { return abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0); } bool isInside(long long x1, long long y1, long long x2, long long y2, long long x3, long long y3, int x, int y) { double A = area(x1, y1, x2, y2, x3, y3); double A1 = area(x, y, x2, y2, x3, y3); double A2 = area(x1, y1, x, y, x3, y3); double A3 = area(x1, y1, x2, y2, x, y); return (A == A1 + A2 + A3); } long long log3(long long n) { long long j = 0; while (n > 0) { n /= 3; j++; } return j - 1; } bool isleap(long long n) { if (n % 4) return 0; else if (n % 100) return 1; else if (n % 400) return 0; else return 1; } bool win(long long a, long long b) { if (a == 0 || b == 0) { return 0; } if (!(b % a) || !(a % b)) { return 1; } if (a > b) { if (!win(a % b, b)) return 1; } else { if (!win(b % a, a)) return 1; } if (a > b) swap(a, b); long long k = b / a; k %= (a + 1); if (k % 2) return 0; return 1; } int main() { FAST(); int test = 1; cin >> test; for (int tt = 1; tt <= test; tt++) { solve(); } return 0; } void solve() { long long a, b; cin >> a >> b; long long ma = max(a, b); long long mi = min(a, b); bool ans = win(ma, mi); if (ans) { cout << "First" << endl; } else cout << "Second" << endl; } long long Rselect(vector<long long> v, long long i, long long l, long long r) { if (l == r) return v[l]; long long pivot = partition(v, l, r); if (pivot == i) return v[pivot - 1]; else if (pivot < i) { return Rselect(v, i, pivot, r); } else { return Rselect(v, i, l, pivot - 2); } } long long partition(vector<long long> v, long long l, long long r) { long long pivot_index = rand() % (r - l + 1) + l; swap(v[pivot_index], v[l]); long long i = l + 1, j = l + 1; while (j <= r) { if (v[j] < v[l]) { swap(v[j], v[i]); i++; } j++; } swap(v[l], v[i - 1]); return i; }
#include <bits/stdc++.h> using namespace std; long long a, b, Test; bool Check(long long x, long long a) { if (a & 1) return (x % (a + 1)) % 2 == 1; else { if (x == a + 1) return false; long long rest = x - a; return ((x % (a + 1)) % 2 == 1) || (rest % (a + 1) == 0); } } bool Dp(long long a, long long b) { if (!a) return false; bool g = Dp(b % a, a); if (!g) return true; else { int cnt = 0; long long x = (b - (a + b % a)) / a; return Check(x, a); } } int main() { scanf("%d", &Test); for (int ii = 0; ii < Test; ++ii) { scanf("%I64d%I64d", &a, &b); if (a > b) swap(a, b); if (Dp(a, b)) printf("First\n"); else printf("Second\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; long long a, b; bool solve(long long x, long long y) { if (!x) return 0; return !solve(y % x, x) || !(y / x % (x + 1) & 1); } int main() { int t; cin >> t; while (t--) { cin >> a >> b; if (a > b) a ^= b ^= a ^= b; puts(solve(a, b) ? "First" : "Second"); } }
#include <bits/stdc++.h> using namespace std; bool myfunction(int i, int j) { return (i < j); } long long t, a, b; bool getAns(long long b, long long a, bool who) { if (b == 0 || a == 0) return !who; if (getAns(a, b % a, !who) == who) return who; long long p = b / a; if (p % (a + 1) % 2 == 0) return who; else return !who; } int main() { cin >> t; while (t--) { cin >> a >> b; if (getAns(max(a, b), min(a, b), 1)) cout << "First" << endl; else cout << "Second" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; bool get(long long a, long long n) { if (n == 0) return true; else if (n == 1) return false; else if (a & 1) { return n % 2 == 0; } else { n -= 2; long long s = a + 1; n %= s; if (n == s - 3 || n == s - 2) return true; else if (n == s - 1) return false; else return n % 2 == 0; } } bool gcd(long long a, long long b) { if (b == 0) return false; bool p = gcd(b, a % b); if (!p) return true; else return get(b, a / b); } int main(void) { int T; cin >> T; while (T--) { long long a, b; cin >> a >> b; if (a < b) swap(a, b); puts(gcd(a, b) ? "First" : "Second"); } }
#include <bits/stdc++.h> using namespace std; int m, n, j, k, l, i, o, p; long long a, b; int solve(long long a, long long b) { if (a < b) swap(a, b); if (b == 0) return 0; if (a % b == 0) return 1; int next = solve(b, a % b); if (next == 0) return 1; int could = 0; a /= b; a--; if (b % 2 == 1 && ((a % (b + 1LL)) % 2 == 1)) could = 1; if (b % 2 == 0) { long long aim = (a % (b + 1LL)); if (aim % 2 == 1 || aim == b) could = 1; } if (could == 1) return 1; return 0; } int main() { cin >> m; for (; m--;) { cin >> a >> b; if (solve(a, b)) printf("First\n"); else printf("Second\n"); } }
#include <bits/stdc++.h> long long Bin(long long x, int bit, long long limit) { long long ret = 1; while (bit) { if (bit & 1) ret = ret * x; x = x * x; bit >>= 1; if (ret > limit || x > limit && bit) return -1; } return ret; } bool dfs(long long a, long long b) { if (a == 0) return false; if (b % a == 0) return true; if (!dfs(b % a, a) || !((b / a % (a + 1)) & 1)) return true; return false; } int main() { int T; long long a, b; scanf("%d", &T); while (T--) { scanf("%I64d%I64d", &a, &b); if (a > b) std::swap(a, b); bool ans = dfs(a, b); puts(ans ? "First" : "Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; bool G[1000]; int casos; long long A[1000], B[1000], hay = 0, uno, dos, m; void va(long long a, long long b) { ++hay; A[hay] = a; B[hay] = b; if (a == 0) return; va(b % a, a); } bool checa(long long num, long long quita) { if (quita % 2 == 1) { if (num % 2 == 0) return true; return false; } num /= quita; if (num <= quita) { if (num % 2 == 0) return true; return false; } num -= quita; num = num % (quita + 1); if (num == 0) num = quita + 1; if (num % 2 == 1) return true; return false; } int main() { scanf("%d", &casos); while (casos--) { scanf("%I64d%I64d", &uno, &dos); if (uno > dos) { m = uno; uno = dos; dos = m; } hay = 0; va(uno, dos); G[hay] = false; for (int i = hay - 1; i > 0; i--) { if (!G[i + 1]) G[i] = true; else G[i] = checa(B[i] - A[i + 1], A[i]); } if (G[1]) printf("First\n"); else printf("Second\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; bool solve(long long a, long long b) { if (a > b) { return solve(b, a); } if (a == 0) { return false; } bool next = solve(b % a, a); if (!next) { return true; } long long c = (b / a); if ((a % 2 == 1)) { return (c % 2 == 0); } else { return (((b / a) % (a + 1)) % 2 == 0); } } inline void init() {} int main() { init(); bool prev = false; int T; while (cin >> T) { if (prev) { cout << endl; } prev = true; long long a, b; for (int i = 0; i < T; i++) { cin >> a >> b; cout << (solve(a, b) ? "First" : "Second") << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; bool gana(long long a, long long b) { if (b < a) swap(a, b); if (a == 0) return false; if (!gana(a, b % a)) return true; long long N = b / a; long long mod = a + 1; return ((N % mod) % 2 == 0); } int main() { int T; cin >> T; long long a, b; for (int i = 0; i < T; i++) { cin >> a >> b; if (gana(a, b)) { puts("First"); } else puts("Second"); } }
#include <bits/stdc++.h> using namespace std; const double OO = 1e9; const double EPS = 1e-6; const int MAXN = 257; bool win(long long a, long long b) { if (a > b) return win(b, a); if (a == 0) return false; if (not win(b % a, a)) return true; return ((b / a) % (a + 1)) % 2 == 0; } int main() { ios_base::sync_with_stdio(0); int n; cin >> n; for (int i = 0; i < (n); ++i) { long long a, b; cin >> a >> b; if (win(a, b)) cout << "First" << endl; else cout << "Second" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long m[100010]; bool check(long long a, long long b) { if (a < b) swap(a, b); int gs = 0; m[gs++] = a; m[gs++] = b; while (b != 0) { m[gs++] = a % b; a = b; b = m[gs - 1]; } bool flag = false; for (int i = gs - 2; i > 0; i--) { if (m[i] % 2 == 1) { if ((m[i - 1] / m[i]) % 2 == 0) { flag = true; } else { flag = !flag; } } else { if (m[i - 1] / m[i] == 1) { flag = !flag; continue; } if (((m[i - 1] / m[i]) % (m[i] + 1)) % 2 == 0) flag = true; else flag = !flag; } } return flag; } int main() { int t; long long a, b; scanf("%d", &t); for (int i = 0; i < t; i++) { scanf("%I64d%I64d", &a, &b); if (check(a, b)) printf("First\n"); else printf("Second\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 7; bool solve(long long a, long long b) { if (a > b) swap(a, b); if (!a) return 0; long long k = b / a; if ((a & 1) && (~k & 1)) return 1; if ((~a & 1)) { k %= (a + 1); if (!k || (~k & 1)) return 1; } return !solve(b % a, a); } int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); int T; cin >> T; while (T--) { long long a, b; cin >> a >> b; if (solve(a, b)) cout << "First" << endl; else cout << "Second" << endl; } return 0; }
#include <bits/stdc++.h> bool check(long long a, long long b) { if (a > b) return check(b, a); if (!a) return false; long long k = b / a; if ((a & 1) && (~k & 1)) return true; if (~a & 1) { k %= (a + 1); if (~k & 1) return true; } return !check(b % a, a); } int main() { int tests; scanf("%d", &tests); while (tests--) { long long a, b; scanf("%lld %lld", &a, &b); puts(check(a, b) ? "First" : "Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; long long a, b; int t; inline bool go(long long x, long long y) { if (!x or !y) return 0; if (x > y) swap(x, y); if (!go(y % x, x)) return 1; return (y / x) % (x + 1) % 2 == 0; } inline void solve() { cin >> a >> b; if (go(a, b)) cout << "First\n"; else cout << "Second\n"; } int main() { ios_base::sync_with_stdio(false); cin >> t; while (t--) solve(); }
#include <bits/stdc++.h> using namespace std; int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; const double PI = acos(-1.0); template <class T> void debug(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; } template <class T> void chmin(T& a, const T& b) { if (a > b) a = b; } template <class T> void chmax(T& a, const T& b) { if (a < b) a = b; } bool iswin(long long int a, long long int b) { if (a == 0) return false; if (!iswin(b % a, a)) return true; long long int dec = (b - b % a) / a; if ((dec % (a + 1)) & 1) return false; return true; } int main() { int t; scanf("%d", &t); while (t--) { long long int a, b; cin >> a >> b; if (a > b) swap(a, b); if (iswin(a, b)) puts("First"); else puts("Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; bool Win(long long a, long long b) { if (a > b) swap(a, b); if (a == 0) return false; bool ok = false; ok |= !Win(b % a, a); if (ok) return true; b /= a; if (a % 2 == 0) { b %= (a + 1); if (b % 2 == 0) return true; else return false; } else { if (b % 2 == 0) return true; else return false; } } int main() { int cases; scanf("%d", &cases); while (cases--) { long long a, b; scanf("%I64d%I64d", &a, &b); if (a > b) swap(a, b); if (Win(a, b)) puts("First"); else puts("Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = (int)(1e9) + 7; const int N = 205; bool fnd(long long a, long long b) { if (!a || !b) return false; if (a > b) swap(a, b); if (!fnd(a, b % a)) return true; long long n = b / a; long long md = a + 1; return !((n % md) & 1); } int main() { int t; long long a, b; scanf("%d", &t); while (t-- > 0) { scanf("%I64d %I64d", &a, &b); bool ans = fnd(a, b); if (ans) puts("First"); else puts("Second"); } }
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } bool calc(long long x, long long y) { if (x > y) swap(x, y); if (x == 0) return 0; if (!calc(x, y % x)) return 1; if (((y / x) % (x + 1)) & 1) return 0; return 1; } int main() { int Test; Test = read(); while (Test--) { long long x, y; x = read(); y = read(); if (calc(x, y)) puts("First"); else puts("Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; int solve(long long a, long long b) { if (!b) return 0; if (solve(b, a % b) == 0) return 1; int t = (a / b) % (b + 1); return t % 2 == 0; } int main() { long long a, b; int test; scanf("%d", &test); for (int i = 1; i <= test; ++i) { scanf("%I64d%I64d", &a, &b); if (a < b) swap(a, b); printf("%s\n", solve(a, b) ? "First" : "Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; int t; long long a, b; bool Win(long long a, long long b) { if (a > b) swap(a, b); if (a == 0LL) return false; if (!Win(b % a, a)) return true; if (a % 2LL) return b / a % 2LL == 0; return b / a % (a + 1LL) % 2LL == 0; } int main() { scanf("%d", &t); while (t--) { scanf("%I64d %I64d", &a, &b); printf(Win(a, b) ? "First\n" : "Second\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; bool dfs(unsigned long long a, unsigned long long b) { if (a > b) { swap(a, b); } if (a == 0) { return false; } if (dfs(a, b % a)) { if (((b / a) % (a + 1)) % 2 == 0) { return true; } return false; } return true; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; for (int i = 0; i < t; i++) { unsigned long long a, b; cin >> a >> b; if (dfs(a, b)) { cout << "First\n"; } else { cout << "Second\n"; } } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native") using namespace std; namespace _c { const double pi = acos(-1.0); const int MIN_INT8 = -128; const int MIN_INT16 = -32768; const int MIN_INT = -2147483647 - 1; const long long MIN_LL = -9223372036854775807LL - 1; const int MAX_INT8 = 127; const int MAX_INT16 = 32767; const int MAX_INT = 2147483647; const long long MAX_LL = 9223372036854775807LL; } // namespace _c namespace _f { template <typename T> inline const T gcd(T m, T n) { while (n != 0) { T t = m % n; m = n; n = t; } return m; } template <typename T> inline const T max(const T &a, const T &b) { return a > b ? a : b; } template <typename T> inline const T min(const T &a, const T &b) { return a < b ? a : b; } template <typename T> inline const T abs(const T &a) { return a > 0 ? a : -a; } } // namespace _f namespace io { template <typename T> inline void read(T &t) { register T res = 0, neg = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) { if (c == '-') { neg = -1; } } for (; isdigit(c); c = getchar()) { res = res * 10 + c - '0'; } t = res * neg; } inline int in() { register int T; read(T); return T; } inline long long in_ll() { register long long T; read(T); return T; } } // namespace io int win(long long a, long long b) { if (!a || !b) { return 0; } if (!win(b % a, a)) { return 1; } if ((b / a % (a + 1)) & 1) { return 0; } else { return 1; } } int main() { int t = io::in(); while (t--) { long long a, b; io::read(a), io::read(b); if (win(_f::min(a, b), _f::max(a, b))) { puts("First"); } else { puts("Second"); } } return 0; }
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; bool f(long long a, long long b) { if (b == 0) return false; return !f(b, a % b) || 1 - a / b % (b + 1) % 2; } int main() { long long a, b, t; cin >> t; while (t--) { cin >> a >> b; cout << (f(max(a, b), min(a, b)) ? "First\n" : "Second\n"); } return 0; }
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; int V[1000]; long long find(long long a, long long b) { long long res = a; double r1 = a; while ((r1 * a) <= (1.0 * b + 1e-9)) { r1 *= a; res *= a; } return res; } int f(long long a, long long b, int idx) { if (a > b) swap(a, b); int res, pb = b; if (res = V[idx]) return res; if (a == 0) res = 2; else { long long nb = b % a, say; say = (b / a) % (a + 1); if (f(a, nb, idx + 1) == 2) res = 1; else res = 2; if ((say % 2 == 0) && f(a, nb, idx + 1) == 1) res = 1; } return V[idx] = res; } int main() { int t; long long a, b; cin >> t; while (t--) { cin >> a >> b; memset(V, 0, sizeof(V)); if (f(a, b, 0) == 1) cout << "First" << endl; else cout << "Second" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; bool f(long long a, long long b) { if (a > b) swap(a, b); if (a * b == 0) return false; if (f(b % a, a) == false) return true; b = b / a; long long mod = a + 1; return ((b % mod) % 2 == 0); } int solve() { long long a, b; scanf("%lld%lld", &a, &b); return f(a, b); } int test; int main() { cin >> test; while (test--) { if (solve() == 1) cout << "First" << endl; else cout << "Second" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long tests, t, qq, q, i, j, bb[200000], s1, ans[2100][2100]; long long a, b; long solve(long long a, long long b) { if (a < b) swap(a, b); if (a == 0 || b == 0) return 0; if (solve(a % b, b) == 0) return 1; t = a / b; if (b % 2 == 1) return 1 - t % 2; t %= (b + 1); if (t % 2 == 1) return 0; return 1; } int main() { long s = 0; cin >> tests; for (; tests; --tests) { cin >> a >> b; if (solve(a, b)) cout << "First" << endl; else cout << "Second" << endl; } cin.get(); cin.get(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef char* cstr; const int oo = (~0u) >> 1; const long long int ooll = (~0ull) >> 1; const double inf = 1e100; const double eps = 1e-8; const double pi = acos(-1.0); template <typename type> inline bool cmax(type& a, const type& b) { return a < b ? a = b, true : false; } template <typename type> inline bool cmin(type& a, const type& b) { return a > b ? a = b, true : false; } template <typename type> inline int sgn(const type& first) { return (first > 0) - (first < 0); } template <> inline int sgn(const double& first) { return (first > +eps) - (first < -eps); } template <typename type> void inc(vector<type>& st, int first, type inc) { while (first < ((int)(st).size())) st[first] += inc, first += (first) & (-(first)); } template <typename type> type sum(vector<type>& st, int first) { type s = 0; while (first > 0) s += st[first], first -= (first) & (-(first)); return s; } bool first(long long int a, long long int b) { long long int aa = a, bb = b; bool result; if (a == 0) result = false; else { if (first(b % a, a)) { b /= a; if (a % 2 == 1) result = b % 2 == 0; else result = b % (a + 1) % 2 == 0; } else result = true; } return result; } int main() { int t; cin >> t; while (t--) { long long int a, b; cin >> a >> b; if (a > b) swap(a, b); cout << (first(a, b) ? "First" : "Second") << endl; } }
#include <bits/stdc++.h> using namespace std; bool ser(long long a, long long b) { if (!a) return 0; if (!ser(b % a, a)) return 1; b /= a; return ((b % (a + 1)) & 1) ? 0 : 1; } int main() { int T; long long a, b; scanf("%d", &T); while (T--) { scanf("%I64d%I64d", &a, &b); if (a > b) swap(a, b); puts(ser(a, b) ? "First" : "Second"); } }
#include <bits/stdc++.h> using namespace std; const char road[1000] = "C:\\data\\"; char roadnum[1000] = ""; char roadin[1000] = ""; char roadout[1000] = ""; void writeIntoFile(char num[]) { strcpy(roadnum, num); strcpy(roadin, road); strcat(roadin, roadnum); strcat(roadin, "."); strcpy(roadout, roadin); strcat(roadin, "in"); strcat(roadout, "out"); freopen(roadin, "r", stdin); freopen(roadout, "w", stdout); } void solve(); void solveM() { char ch[50]; for (int i = 1; i <= 30; i++) { sprintf(ch, "%d", i); writeIntoFile(ch); solve(); } } const long long M = 1e18; const long long MT = 1e4; bool isFirst(long long a, long long b) { if (a > b) swap(a, b); if (a == 0) return false; if (!isFirst(b % a, a)) return true; return ((b / a) % (a + 1)) % 2 == 0; } void solve() { long long a, b; int T; int ioflag = -1; ioflag = scanf("%d", &T); assert(ioflag == 1); assert(1 <= T && T <= MT); while (T--) { scanf("%lld%lld", &a, &b); assert(0 <= a && a <= M); assert(0 <= b && b <= M); if (isFirst(a, b)) { puts("First"); } else { puts("Second"); } } } int main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; long long t, a, b; int f(long long a, long long b) { if (a == 0 || b == 0) return 0; if (a < b) swap(a, b); if (f(b, a % b) == 0) return 1; return (a - a % b) / b % (b + 1) % 2 ? 0 : 1; } int main() { cin >> t; for (int i = 0; i < t; i++) { cin >> a >> b; cout << (f(a, b) ? "First\n" : "Second\n"); } }
#include <bits/stdc++.h> using namespace std; bool win(long long a, long long b) { if (a > b) swap(a, b); if (a == 0) return false; if (!win(a, b % a)) return true; long long x = b / a; if (x % (a + 1) % 2 == 0) return true; else return false; } int main() { long long a, b; int T; scanf("%d", &T); while (T--) { scanf("%I64d%I64d", &a, &b); win(a, b) ? puts("First") : puts("Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; long long test, a, b; long long get(long long y, long long x) { long long sum = 0; while (x > 0) { sum += x % y; x /= y; } if (sum % 2 == 0) return true; else { return false; } } bool check(long long a, long long b) { if (a > b) swap(a, b); if (a == 0) return false; if (check(a, b % a) == true) { long long t = (b / a) % (a + 1); if (t % 2 == 0) { return true; } return false; } return true; } int main() { cin >> test; while (test--) { cin >> a >> b; if (check(a, b) == true) { cout << "First"; } else { cout << "Second"; } cout << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } const int INF = 1 << 29; inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return n & two(b); } inline void set_bit(int& n, int b) { n |= two(b); } inline void unset_bit(int& n, int b) { n &= ~two(b); } inline int last_bit(int n) { return n & (-n); } inline int ones(int n) { int res = 0; while (n && ++res) n -= n & (-n); return res; } template <class T> void chmax(T& a, const T& b) { a = max(a, b); } template <class T> void chmin(T& a, const T& b) { a = min(a, b); } int gcd(long long a, long long b) { if (a > b) swap(a, b); if (!a) return 0; if (!gcd(b % a, a)) return 1; b /= a; return b % (a + 1) % 2 == 0; } int main() { int T; scanf("%d", &T); while (T--) { long long a, b; cin >> a >> b; if (!a || !b) { printf("Second\n"); continue; } if (a == 1 || b == 1) { printf("First\n"); continue; } if (gcd(a, b)) printf("First\n"); else printf("Second\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000; long long mod = 1000000007LL; long long mod2 = 998244353LL; int t; long long a, b; bool getgcd(long long x, long long y) { if (x > y) return getgcd(y, x); if (x == 0) return false; bool res = getgcd(y % x, x); if (!res) return true; long long z = y / x; if (x % 2) return (z % 2 == 0); return (z % (x + 1) % 2 == 0); } int main() { cin >> t; for (int cas = 1; cas <= t; ++cas) { cin >> a >> b; bool res = getgcd(a, b); if (res) cout << "First" << endl; else cout << "Second" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; bool solve(long long a, long long b) { if (a > b) swap(a, b); if (!a) return 0; if (!solve(a, b % a)) return 1; long long x = b / a; if (!(a & 1)) return !((x % (a + 1)) & 1); else return !(x & 1); } int main() { int t; scanf("%d", &t); for (int it = 0; it < t; it++) { long long a, b; scanf("%I64d%I64d", &a, &b); if (a > b) swap(a, b); printf(solve(a, b) ? "First\n" : "Second\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; char Ans[2][100] = {"Second", "First"}; int solve(long long a, long long b) { if (a > b) swap(a, b); if (a == 0) return 0; if (!solve(a, b % a)) return 1; long long t = b / a; return (t % (a + 1)) % 2 == 0; } int main() { int T; for (cin >> T; T--;) { long long a, b; cin >> a >> b; printf("%s\n", Ans[solve(a, b)]); } }
#include <bits/stdc++.h> using namespace std; long long dfs(long long x, long long y) { if (x > y) { swap(x, y); } if (!x) { return 0; } if (dfs(y % x, x)) { return (((y / x) % (x + 1)) % 2 == 0); } else { return 1; } } int32_t main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); long long t; cin >> t; while (t--) { long long x, y; cin >> x >> y; cout << (dfs(x, y) ? "First\n" : "Second\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; bool solve(long long a, long long b) { if (a > b) swap(a, b); if (!a) return 0; bool bad = solve(a, b % a); if (!bad) return 1; long long moves = b / a - 1; if (a % 2) return moves % 2; moves %= (a + 1); if (moves == a) return 1; return moves % 2; } int main() { int test_num; long long a, b; scanf("%d", &test_num); for (; test_num--;) { scanf("%I64d%I64d", &a, &b); if (solve(a, b)) puts("First"); else puts("Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; bool can(long long A, long long B) { if (A % 2) { long long r = 0; while (B > 0) { r += B % A; B /= A; } return r % 2 == 0; } else { long long r = B % (A + 1); return r % 2 == 0; } } bool solve(long long A, long long B) { if (B < A) swap(A, B); if (A == 0) return false; if (!solve(B % A, A)) return true; if (can(A, B / A)) return true; return false; } bool solveslow(long long A, long long B) { if (B < A) swap(A, B); if (A == 0) return false; if (!solve(B % A, A)) return true; for (long long r = 1; r <= B; r *= A) { if (!solve(A, B - r)) { return true; } } return false; } int main() { int T; cin >> T; for (int t = 1; t <= T; t++) { long long A, B; cin >> A >> B; cout << (solve(A, B) ? "First" : "Second") << endl; } }
#include <bits/stdc++.h> using namespace std; const int inv = 1000000000; const int minv = -inv; char process(long long a, long long b) { if (a == 0ll) return 'L'; if (process(b % a, a) == 'L') return 'W'; else { long long k = (b - (b % a)) / a; if ((k % (a + 1ll)) % 2ll) return 'L'; else return 'W'; } } int main() { int T; scanf("%d", &T); for (int z = 0; z < T; ++z) { long long a, b; cin >> a; cin >> b; if (a > b) swap(a, b); if (process(a, b) == 'L') printf("Second\n"); else printf("First\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; long long int c, casos, a, b, i, j; bool gan(long long int a, long long int b) { if (a > b) { swap(a, b); } if (a == 0) return false; if (a == 1) return true; if (b % a == 0) { return true; } bool nex = gan(b % a, a); if (!nex) { return true; } else { long long int x = b / a; if ((x % 2 == 0) && (a % 2 != 0)) { return true; } if ((x % 2 != 0) && (a % 2 != 0)) { return false; } if (a % 2 == 0) { x = x % (a + 1); if (x % 2 == 0) return true; else return false; } } } int main() { scanf("%I64d", &casos); for (c = 0; c < casos; c++) { scanf("%I64d%I64d", &a, &b); if (gan(a, b)) { printf("First\n"); } else { printf("Second\n"); } } }
#include <bits/stdc++.h> using namespace std; bool myfunction(int i, int j) { return (i < j); } long long t, a, b; bool getAns(long long b, long long a, bool who) { if (b == 0 || a == 0) return !who; if (getAns(a, b % a, !who) == who) return who; long long p = b / a; if (p % (a + 1) % 2 == 0) return who; else return !who; } int main() { cin >> t; while (t--) { scanf("%I64d%I64d", &a, &b); if (getAns(max(a, b), min(a, b), 1)) cout << "First" << endl; else cout << "Second" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int calc(long long a, long long b) { if (a > b) swap(a, b); if (a == 0) return 0; if (!calc(b % a, a)) return 1; return ~((b / a) % (a + 1)) & 1; } int main() { int T; long long a, b; for (scanf("%d", &T); T--;) { scanf("%I64d%I64d\n", &a, &b); puts(calc(a, b) ? "First" : "Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; bool solver(long long a, long long b); bool solver(long long a, long long b) { if (a > b) { long long tmp; tmp = a; a = b; b = tmp; } if (a == 0) return false; else if (!solver(b % a, a)) return true; else { if (a % 2) { if ((b - b % a) % 2) return false; else return true; } else { if ((b / a) % (a + 1) % 2) return false; else return true; } } } int main() { int t; cin >> t; for (int i = 1; i <= t; i++) { long long a, b; cin >> a >> b; if (solver(a, b)) cout << "First" << endl; else cout << "Second" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long inf = 0x3f3f3f3f; void dfs(long long a, long long b, int f) { if (b > a) swap(a, b); if (a == 0 || b == 0) { if (f == 1) printf("Second\n"); else printf("First\n"); return; } if (a % b == 0) { if (f == 1) printf("First\n"); else printf("Second\n"); return; } if ((a / b % (b + 1)) % 2 == 0) { if (f == 1) printf("First\n"); else printf("Second\n"); return; } dfs(a % b, b, 1 - f); } void slove(long long a, long long b) { dfs(a, b, 1); } int main() { int t; cin >> t; while (t--) { long long a, b; cin >> a >> b; slove(a, b); } return 0; }
#include <bits/stdc++.h> using namespace std; bool win(long long a, long long b) { if (a == 0) return false; if (b % a == 0 || !win(b % a, a)) return true; else return (b / a) % (a + 1) % 2 == 0; } int main() { int T; long long a, b; cin >> T; while (T--) { cin >> a >> b; if (a > b) swap(a, b); cout << (win(a, b) ? "First" : "Second") << endl; } }
#include <bits/stdc++.h> using namespace std; bool gao(long long a, long long b) { if (a > b) swap(a, b); if (!a) return false; if (!gao(b % a, a)) return true; return b / a % (a + 1) % 2 == 0; } int main() { int T; scanf("%d", &T); while (T--) { long long a, b; scanf("%I64d%I64d", &a, &b); puts(gao(a, b) ? "First" : "Second"); } }
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int N = 3e5; vector<int> g[N]; int a[N]; int mpow(int base, int exp); void ipgraph(int n, int m); void dfs(int u, int par); map<pair<long long, long long>, int> dp; int go(long long a, long long b) { if (a < b) swap(a, b); if (dp.find({a, b}) != dp.end()) return dp[{a, b}]; if (b == 0) return 0; if (a % b == 0) return 1; int ans = go(a % b, b); if (!ans) return dp[{a, b}] = 1; long long b_ = a / b; if (b & 1) return dp[{a, b}] = 1 - (b_ & 1); b_ %= (b + 1); if (b_ & 1) return dp[{a, b}] = 0; return dp[{a, b}] = 1; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int i, n, k, j; int t; cin >> t; while (t--) { long long x, y; cin >> x >> y; int win = go(x, y); if (win) cout << "First\n"; else cout << "Second\n"; } return 0; } int mpow(int base, int exp) { base %= mod; int result = 1; while (exp > 0) { if (exp & 1) result = ((long long)result * base) % mod; base = ((long long)base * base) % mod; exp >>= 1; } return result; } void ipgraph(int n, int m) { int i, u, v; while (m--) { cin >> u >> v; g[u - 1].push_back(v - 1); g[v - 1].push_back(u - 1); } } void dfs(int u, int par) { for (int v : g[u]) { if (v == par) continue; dfs(v, u); } }
#include <bits/stdc++.h> using namespace std; bool win[1000001]; bool Force(long long int b, long long int a) { win[0] = true; cerr << "a=" << a << " b=" << b << endl; for (long long int i = 1; i <= b; ++i) { win[i] = false; for (long long int t = 1;; t *= a) { if (!win[i - t]) { win[i] = true; break; } if (t > i / a) break; } } cerr << "win[b]" << "=\"" << win[b] << "\"" << " at line#" << 34 << endl; ; return win[b]; } bool AntiNim(long long int b, long long int a) { assert(b > 0); if (a & 1) return !((b & 1)); long long int k = (b - 1) / (a + 1); b -= k * (a + 1) + 1; assert(b >= 0); return (b & 1) || (b + 1 == a + 1); } bool solve(long long int a, long long int b) { if (a > b) swap(a, b); if (a == 0) return false; if (!solve(a, b % a)) return true; return AntiNim(b / a, a); } int main() { int t; cin >> t; for (int i = 0; i < (t); ++i) { long long int a, b; cin >> a >> b; cout << (solve(a, b) ? "First" : "Second") << endl; } return 0; }