text stringlengths 49 983k |
|---|
/*
~2021~
*/
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
#define pii pair<int,int>
const int N = 1e7 ;
const int INF = 1e9;
const ll mod = 1e9+7;
int primeterkecil[N + 5],ans[N + 5];
ll sum[N + 5];
void sieve(){
primeterkecil[1] = 1;
for(int i = 2;i * i<=N;i++){
if(primeterkecil[i] != 0) continue;
primeterkecil[i] = i;
for(int j = i * i;j<=N;j += i){
if(primeterkecil[j] == 0) primeterkecil[j] = i;
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen(,r,stdin);
//freopen(,w,stdout);
sieve();
for(int i = 1;i<=N;i++) sum[i] = 1;
for(int i = 2;i<=N;i++){
if(primeterkecil[i] == 0){
primeterkecil[i] = i;
sum[i] = i + 1;
}
else{
int temp = i;
while(temp % primeterkecil[i] == 0){
//cout<<temp<<endl;
temp/=primeterkecil[i];
sum[i] = sum[i] * primeterkecil[i] + 1;
}
sum[i] *= sum[temp];
}
}
memset(ans,-1,sizeof(ans));
for(int i = 1;i<=N;i++){
if(sum[i] <= N && ans[sum[i]] == -1) ans[sum[i]] = i;
}
int t;
cin>>t;
while(t--){
int n;
cin>>n;
cout<<ans[n]<<'\n';
}
} |
#include<bits/stdc++.h>
//#define int long long
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define pii pair<int,int>
#define float double
#define pb push_back
#define lp(i,j,n) for( i=j;i<n;i++)
#define lop(j,k,n)for( j=k;j<n;j++)
#define m_p make_pair
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define minheap priority_queue<int,vector<int>,greater<int>>
#define maxheap priority_queue<int>
#define kickstart cout<<"Case #"<<tt<<": "
#define pair_pq priority_queue<pii,vector<pii> ,greater<pii>>
#define ff first
#define ss second
#define pff pair<float,float>
typedef long long ll;
typedef long double ld ;
#define pll pair<ll , ll>
#define piii pair<int,pii>
#define all(x)x.begin(),x.end()
#define vi vector<int>
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) \
for ( \
auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
blockTime.second; \
debug("%s: %d ms\n", d, (int)chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false \
)
int dx[4] = { 1 , -1 , 0 , 0 };
int dy[4] = { 0 , 0 , 1 , -1};
void show(vector<ll> a){for(auto x :a )cout<<x <<" ";}
const ll M =2e3 + 5,mod = 998244353 ,MOD = 1e9 + 7 , inf =1e18 , MAX = 2e5 + 5 ;
string alph = "abcdefghijklmnopqrstuvwxyz";
map<ll,ll>mp;
const int N = 10000000 +10;
int lp[N+1];
ll dp[N +1];
vector<int> pr , ans(N , -1);
void linear_SIEVE(){
for (int i=2; i<=N; ++i) {
if (lp[i] == 0) {
lp[i] = i;
pr.push_back (i);
}
for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
lp[i * pr[j]] = pr[j];
}
}
void precompute()
{
dp[1] = 1;
for(ll i = 2 ; i < N ; i++)
{
if(lp[i] == i)
{
dp[i] = i + 1;
// if(!mp[dp[i]])mp[dp[i]] = i;
continue;
}
int j = i ;
dp[i] = 1;
while(j%lp[i] == 0)
{
dp[i] = dp[i]*lp[i] + 1 ;
j/=lp[i];
}
dp[i]*=dp[j];
//if(!mp[dp[i]])mp[dp[i]] = i;
}
}
void solve(int tt ){
ll i , j , n , m ;
int l , r , s ;
cin >> n ;
cout << ans[n] <<"\n";
}
signed main()
{
fastio
ll i ;
ll T = 1 ;
//
//
linear_SIEVE();
precompute();
for(int i = N - 1; i >= 1 ; i--)
if(dp[i] < N)
{
ans[dp[i]] = i;
}
cin >> T ;
time__("Exec Time : "){
ll x = 1 ;
while( x <= T ){
solve(x);
x++;
}
}
return 0;
}
/*
1 --> DO NOT STAY STUCK ON ONE APPROACH
2 --> DO NOT SIT IDLE . DO SMTHING
3 --> STAY ORGANISED .
vector<bool>taken(n+1 , false);
for(int j = l ; j <= r ; j--)
taken[a[j]] = true;
vi avail ;
lp( j , 1, n + 1)if(!taken[j])avail.pb(j);
lp( j , 1 , n + 1){ if(a[j] == 0){ a[j] = avail.back() ; avail.pop_back();} cout << a[i] <<" ";}
cout <<endl;
*/
|
#include <bits/stdc++.h>
using namespace std;
const int N = (int) 1e7 + 10;
long long s[N];
int d[N];
int ans[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
fill(d, d + N, -1);
d[1] = 1;
for (int i = 2; i * i < N; i++) {
if (d[i] == -1) {
d[i] = i;
for (int j = i * i; j < N; j += i) {
if (d[j] == -1) {
d[j] = i;
}
}
}
}
s[1] = 1;
for (int i = 2; i < N; i++) {
if (d[i] == -1) {
d[i] = i;
s[i] = i + 1;
} else {
int j = i;
s[i] = 1;
while (j % d[i] == 0) {
j /= d[i];
s[i] = s[i] * d[i] + 1;
}
s[i] *= s[j];
}
}
fill(ans, ans + N, -1);
for (int i = N - 1; i > 0; i--) {
if (s[i] < N) {
ans[s[i]] = i;
}
}
int tests;
cin >> tests;
while (tests-- > 0) {
int c;
cin >> c;
cout << ans[c] << endl;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
bool check(long long a, long long b) {
if (!a || !b) return false;
if (a > b) swap(a, b);
if (!check(a, b % a)) return true;
return !(((b / a) % (a + 1)) & 1);
}
int main() {
int T;
cin >> T;
for (; T; --T) {
long long a, b;
cin >> a >> b;
printf("%s\n", (check(a, b)) ? "First" : "Second");
}
}
|
#include <bits/stdc++.h>
using namespace std;
bool get(long long a, long long b) {
if (a < b) swap(a, b);
if (b == 0) return 0;
if (!get(b, a % b)) return 1;
if (b % 2)
return a / b % 2 == 0;
else
return a / b % (b + 1) % 2 == 0;
}
int main() {
int t;
long long a, b;
for (scanf("%d", &t); t--; scanf("%I64d%I64d", &a, &b),
printf("%s\n", get(a, b) ? "First" : "Second"))
;
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long a, b;
bool go(long long a, long long b) {
if (a == 0 || b == 0) return false;
if (a > b) swap(a, b);
if (!go(a, b % a)) return true;
long long moves = (b / a);
if (a % 2 == 1) {
return (moves % 2) == 0;
} else {
long long res = (moves % (a + 1));
return (res % 2 == 0);
}
}
void solve() {
cin >> a >> b;
bool who = go(a, b);
if (who)
cout << "First" << '\n';
else
cout << "Second" << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int tst;
cin >> tst;
while (tst--) solve();
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 == 0) return false;
bool next = solve(a, b % a);
if (!next) return true;
long long num = b / a;
if (a % 2 == 1)
return num % 2 == 1 ? false : true;
else {
long long m = a + 1;
num -= 1;
long long rem = num % m;
if (rem == m - 1) return true;
if (rem % 2 == 0)
return false;
else
return true;
}
}
int main() {
int t;
cin >> t;
for (int i = 0; i < t; ++i) {
long long a, b;
cin >> a >> b;
if (a > b) swap(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) return false;
long long na, nb;
na = b % a;
nb = a;
if (!win(na, nb)) return true;
long long num = b / a;
if (a % 2 == 1) {
return (num % 2 == 0);
}
num %= (a + 1);
return (num % 2 == 0);
}
int main() {
int i, j;
int t;
cin >> t;
for (i = 0; i < t; ++i) {
long long a, b;
cin >> a >> b;
if (a > b) swap(a, b);
if (win(a, b))
cout << "First" << endl;
else
cout << "Second" << endl;
}
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 ((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;
bool debug = false;
bool dfs(long long a, long long b) {
if (b < a) {
swap(a, b);
}
if (a == 0) {
return false;
}
bool mod = dfs(a, b % a);
if (!mod) {
return true;
}
long long t = b / a;
return t % (a + 1) % 2 == 0;
}
int main(int argc, char* argv[]) {
int t;
cin >> t;
while (t--) {
long long a, b;
cin >> a >> b;
cout << (dfs(a, b) ? "First" : "Second") << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
bool Solve(long long a, long long b) {
if (!a) return false;
if (!Solve(b % a, a)) return true;
long long t = b / a - 1;
return ((t + 1) % (a + 1)) % 2 == 0;
}
int main() {
int T;
long long a, b, t;
scanf("%d", &T);
while (T--) {
scanf("%lld%lld", &a, &b);
if (a > b) t = a, a = b, b = t;
printf(Solve(a, b) ? "First\n" : "Second\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
bool ok(long long x, long long y) {
if (x > y) swap(x, y);
if (x == 0) return 0;
if (!ok(x, y % x)) return 1;
long long d = (y / x);
return ((d % (x + 1LL)) % 2 + 100) % 2 == 0;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
long long x, y;
cin >> x >> y;
puts(ok(x, y) ? "First" : "Second");
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long int cal(long long int a, long long int b) {
if (a == 0 || b == 0) return false;
if (b % a == 0) return true;
long long int flag = cal(b % a, a);
if (!flag) return true;
return ((b / a) % (a + 1)) % 2 == 0;
}
int main() {
long long int t;
cin >> t;
while (t--) {
long long int a, b;
cin >> a >> b;
if (cal(min(a, b), max(a, b)))
cout << "First" << endl;
else
cout << "Second" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
bool calc(long long a, long long b) {
if (a == 0) return 0;
if (!calc(b % a, a)) return 1;
if (a & 1) return !((b / a) & 1);
return !((b / a % (a + 1)) & 1);
}
int main() {
int tc;
scanf("%d", &tc);
while (tc--) {
long long a, b;
scanf("%lld%lld", &a, &b);
if (a > b) swap(a, b);
puts(calc(a, b) ? "First" : "Second");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int ni() {
int a;
scanf("%d", &a);
return a;
}
double nf() {
double a;
scanf("%lf", &a);
return a;
}
char sbuf[100005];
string ns() {
scanf("%s", sbuf);
return sbuf;
}
long long nll() {
long long a;
scanf("%lld", &a);
return a;
}
template <class T>
void out(T a, T b) {
bool first = true;
for (T i = a; i != b; ++i) {
if (!first) printf(" ");
first = false;
cout << *i;
}
printf("\n");
}
template <class T>
void outl(T a, T b) {
for (T i = a; i != b; ++i) {
cout << *i << "\n";
}
}
int n, m;
bool moo(long long a, long long b) {
if (a > b) swap(a, b);
if (!a) return false;
if (!moo(a, b % a)) return true;
long long k = (b - b % a) / a;
if (a % 2) {
return k % 2 == 0;
}
return ((k % (a + 1)) % 2 == 0);
}
int main() {
int i, j, k;
for (n = ni(); n; --n) {
long long a = nll();
long long b = nll();
printf("%s\n", moo(a, b) ? "First" : "Second");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int solve(long long a, long long b) {
if (a == 0 || b == 0) return 0;
if (a > b) swap(a, b);
if (solve(a, b % a) == 0) return 1;
long long k = (b / a - 1) % (a + 1);
return k & 1 || k == a;
return 0;
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
long long a, b;
scanf("%lld%lld", &a, &b);
printf(solve(a, b) ? "First\n" : "Second\n");
}
return 0;
}
|
#include <bits/stdc++.h>
bool win(long long x, long long y) {
if (x > y) x ^= y, y ^= x, x ^= y;
if (!x) return false;
if (!win(y % x, x)) return true;
return ~((y / x) % (x + 1)) & 1;
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
long long x, y;
scanf("%I64d%I64d", &x, &y);
puts(win(x, y) ? "First" : "Second");
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:128000000")
using namespace std;
const double PI = acos(-1.0);
template <class T>
T SQR(const T &a) {
return a * a;
}
bool win(unsigned long long a, unsigned long long b) {
if (a == 0 || b == 0) return false;
if (a < b) swap(a, b);
if (a % b == 0) return true;
if (!win(b, a % b)) return true;
a = (a - a % b) - 1;
if (b & 1) return a % (2 * b) >= b;
if (double(b) * b < 3e18) a %= b * (b + 1);
if (double(b) * b > 3e18 || a < b * b) return a % (2 * b) >= b;
return true;
}
void run() {
int t;
cin >> t;
for (int i = (0), ei = (t); i < ei; i++) {
unsigned long long a, b;
cin >> a >> b;
puts(win(a, b) ? "First" : "Second");
}
}
int main() {
time_t beg = clock();
run();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool gcd(long long a, long long b) {
if (b == 0 || a == 0) return 0;
if (b % a == 0) return 1;
if (!gcd(b % a, a)) return 1;
if (a & 1) {
if ((b / a) % 2) return 0;
return 1;
}
b /= a;
if (b % (a + 1) == 0) return 1;
b %= a + 1;
if (b % 2 == 0) return 1;
return 0;
}
int main() {
long long a, b;
int t;
cin >> t;
while (t--) {
cin >> a >> b;
if (a == 0 || b == 0)
cout << "Second\n";
else {
if (a >= b) {
long long t = a;
a = b, b = t;
}
if (gcd(a, b))
cout << "First\n";
else
cout << "Second\n";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int gao(long long x, long long y) {
if (x < y) swap(x, y);
if (!y) return 0;
if (!gao(y, x % y)) return 1;
int sg = 0;
x /= y;
if (y % 2)
return (x % 2 == 0);
else
return (x % (y + 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");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int gana(long long int a, long long int b) {
if (a == 0 or b == 0) return 2;
if (b < a) swap(a, b);
if (gana(b % a, a) == 2) return 1;
b /= a;
b--;
if (a % 2 == 1) {
if (b % 2 == 1)
return 1;
else
return 2;
}
long long int modulo = b % (a + 1);
if (modulo == a or modulo % 2 == 1) return 1;
return 2;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
long long int a, b;
cin >> a >> b;
if (gana(a, b) == 1) {
cout << "First" << endl;
} else {
cout << "Second" << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
map<pair<long long, long long>, long long> mmp;
long long a, b;
int DFS(long long a, long long b) {
if (a > b) swap(a, b);
if (!a) return 0;
long long c = b % a;
if (DFS(a, c) == 0) {
return 1;
} else {
long long k = b / a;
if ((k % (a + 1)) % 2 == 0)
return 1;
else
return 0;
}
}
int main() {
int Cas;
cin >> Cas;
while (Cas--) {
cin >> a >> b;
cout << (DFS(a, b) == 1 ? "First" : "Second") << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int f(long long m, long long k) {
long long cnt = m / (k + 1);
if (cnt & 1) {
if (m & 1)
return 1;
else
return 0;
} else {
if (m & 1)
return 0;
else
return 1;
}
}
int rec(long long v, long long k) {
if (k == 0) return 1;
if (v % k == 0) return 0;
int r = rec(k, v % k);
if (r) return 0;
if (!(k & 1)) {
if (f(v / k, k))
return 0;
else
return 1;
} else {
if ((v / k) & 1)
return 1;
else
return 0;
}
}
int main() {
int t;
long long a, b;
scanf("%d", &t);
for (int i = 0; i < t; ++i) {
scanf("%I64d%I64d", &a, &b);
if (rec(max(a, b), min(a, b)))
printf("Second");
else
printf("First");
printf("\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool win(long long a, long long b) {
if (!a || !b) return false;
if (!win(b, a % b)) return true;
long long d = a / b;
long long e = b + 1;
return ((d % e) % 2 == 0);
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
long long a, b;
cin >> a >> b;
if (a < b) swap(a, b);
if (win(a, b))
printf("First\n");
else
printf("Second\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 103;
bool dp[N][N];
bool stg(long long a, long long b) {
if (a > b) swap(a, b);
if (a == 0) return false;
if (!stg(b % a, a)) return true;
if (a % 2 == 1) {
return ((b / a) % 2 == 0);
}
return (((b / a) % (a + 1)) % 2 == 0);
}
void solv() {
int qq;
scanf("%d", &qq);
while (qq--) {
long long a, b;
scanf("%lld%lld", &a, &b);
if (stg(a, b))
printf("First\n");
else
printf("Second\n");
}
return;
for (int i = 1; i < N; ++i) {
for (int j = 1; j < N; ++j) {
if (i > j) {
if (!dp[i % j][j]) {
dp[i][j] = true;
continue;
}
for (int x = j; x <= i; x *= j) {
if (!dp[i - x][j]) {
dp[i][j] = true;
break;
}
}
} else {
if (!dp[i][j % i]) {
dp[i][j] = true;
continue;
}
for (int x = i; x <= j; x *= i) {
if (!dp[i][j - x]) {
dp[i][j] = true;
break;
}
}
}
}
}
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
printf("%d", dp[i][j]);
}
printf("\n");
}
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
if (stg(i, j) != dp[i][j]) {
printf("WA\n");
}
}
}
}
int main() {
solv();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int iinf = 1e9 + 7;
const long long linf = 1ll << 60;
const double dinf = 1e10;
template <typename T>
inline void scf(T &x) {
bool f = 0;
x = 0;
char c = getchar();
while ((c < '0' || c > '9') && c != '-') c = getchar();
if (c == '-') {
f = 1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
if (f) x = -x;
return;
}
template <typename T1, typename T2>
void scf(T1 &x, T2 &y) {
scf(x);
return scf(y);
}
template <typename T1, typename T2, typename T3>
void scf(T1 &x, T2 &y, T3 &z) {
scf(x);
scf(y);
return scf(z);
}
inline bool solve(long long a, long long b) {
if (a > b) swap(a, b);
if (!a) return 0;
bool f = solve(a, b % a);
if (!f) return 1;
long long x = b / a;
if (a & 1) return (x & 1) ^ 1;
x %= (a + 1);
return (x & 1) ^ 1;
}
int main() {
int T;
scf(T);
while (T--) {
long long a, b;
scf(a, b);
puts(solve(a, b) ? "First" : "Second");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool gcd(long long a, long long b) {
if (!b) return false;
if (!gcd(b, a % b))
return true;
else {
if (b % 2 == 1)
return (a / b + 1) % 2;
else {
a /= b;
a--;
if (a % (b + 1) == b)
return true;
else
return a % (b + 1) % 2;
}
}
}
int main() {
int test;
for (cin >> test; test; test--) {
long long a, b;
cin >> a >> b;
if (gcd(max(a, b), min(a, b)))
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) || (c <= a)) {
return (c % 2 == 0);
} else {
return ((c % (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;
int gao(long long a, long long b) {
if (a > b) a ^= b ^= a ^= b;
if (!a) return 0;
return !(b / a % (a + 1) % 2 && gao(b % a, a));
}
int main() {
int cs;
scanf("%d", &cs);
while (cs--) {
long long a, b;
scanf("%I64d%I64d", &a, &b);
puts(gao(a, b) ? "First" : "Second");
}
}
|
#include <bits/stdc++.h>
using namespace std;
bool g(long long int n, long long int m) {
if (n % 2 == 0) {
long long int k = m % (n + 1);
return (k % 2 == 0);
} else {
return (m % 2 == 0);
}
}
bool f(long long int n, long long int m) {
if (n == 0) return false;
return (g(n, m / n) || (!f(m % n, n)));
}
int main() {
int t;
long long int a, b;
cin >> t;
for (int i = 0; i < t; i++) {
cin >> a >> b;
if (f(min(a, b), max(a, b))) {
cout << "First\n";
} else {
cout << "Second\n";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long w(long long a, long long b) {
if (!a | !b) return 0;
if (a > b) swap(a, b);
if (!w(a, b % a)) return 1;
return !(((b / a) % (a + 1)) % 2);
}
int main() {
long long t, a, b;
cin >> t;
while (t--) {
cin >> a >> b;
cout << (w(a, b) ? "First" : "Second") << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
bool dfs(long long a, long long b) {
if (a == 0 || b == 0) return false;
if (a > b) swap(a, b);
if (!dfs(a, b % a)) return true;
return !(b / a % (a + 1) % 2);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long a, b, t;
cin >> t;
while (t--) {
cin >> a >> b;
cout << (dfs(a, b) ? "First" : "Second") << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T abs(T a) {
return a > 0 ? a : -a;
}
int n;
int m;
string ans[2] = {"First", "Second"};
int gom(long long a, long long b) {
if (a == 0) {
return 0;
}
int p = gom(b % a, a);
if (p == 0) {
return 1;
}
long long k = b / a;
if (a % 2) {
return 1 - (k % 2);
} else {
k %= (a + 1);
return 1 - (k % 2);
}
}
int main() {
int t;
cin >> t;
for (int I = 0; I < (t); I++) {
long long a, b;
cin >> a >> b;
if (a > b) swap(a, b);
cout << ans[1 - gom(a, b)] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
long long x, y, t;
int F(long long x, long long y) {
return x < y ? F(y, x) : y && (!F(x % y, y) || 1 - x / y % (y + 1) % 2);
}
int main() {
for (std::cin >> t; t--;)
std::cin >> x >> y, puts(F(x, y) ? "First" : "Second");
}
|
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
int dblcmp(double d) {
if (fabs(d) < eps) return 0;
return (d > 0) ? 1 : -1;
}
int n, m, T;
bool win(long long a, long long b) {
if (a * b == 0) return false;
if (a > b) swap(a, b);
if (!win(a, b % a)) return 1;
return ((b / a) % (a + 1)) % 2 == 0;
}
int main() {
cin >> T;
while (T--) {
long long a, b;
cin >> a >> b;
if (win(a, b))
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) return 0;
if (!solve(b % a, a)) return 1;
return ((b / a) % (a + 1) + 1) % 2;
}
int main() {
int T;
scanf("%d", &T);
long long a, b;
while (T--) {
cin >> a >> b;
if (a > b) swap(a, b);
if (solve(a, b))
puts("First");
else
puts("Second");
}
}
|
#include <bits/stdc++.h>
using namespace std;
int calc(long long a, long long b) {
long long c = b % a;
if (c == 0) return 1;
int x = calc(c, a);
if (!x) return 1;
b = b / a;
if (a % 2) return !(b % 2);
b %= (a + 1);
if (b == 0 or b == 2) return 1;
return !(b % 2);
}
int main() {
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
long long a, b;
cin >> a >> b;
if (a > b) swap(a, b);
if (a == 0) {
puts("Second");
continue;
}
if (calc(a, b))
puts("First");
else
puts("Second");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
inline int gcd(long long a, long long b) {
if (a > b) swap(a, b);
if (a == 0) return 0;
int lpr = gcd(a, b % a);
if (lpr == 0) return 1;
return ~((b / a) % (a + 1)) & 1;
}
inline string solve(long long a, long long b) {
if (a > b) swap(a, b);
return gcd(a, b) ? "First" : "Second";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
int T;
cin >> T;
long long a, b;
while (T--) {
cin >> a >> b;
cout << solve(a, b) << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int check(long long a, long long b) {
if (a == 0) return 0;
if (check(b % a, a)) {
b /= a;
return !((b % (a + 1)) & 1);
}
return 1;
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
long long a, b;
cin >> a >> b;
if (a > b) swap(a, b);
if (check(a, b))
cout << "First" << endl;
else
cout << "Second" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long i, j, k, l, m, n, c, s, t, p, q, a, b, aa, bb, d;
long long ni(long long aa, long long bb) {
long long tt = 0;
while (aa > 0) {
tt += aa % bb;
aa /= bb;
}
return tt;
}
int main() {
cin >> n;
while (n--) {
cin >> a >> b;
t = 0;
if (a == 0 || b == 0) cout << "Second";
while (a > 0 && b > 0) {
if (a < b) swap(a, b);
if (a % b == 0) {
if (t == 0)
cout << "First";
else
cout << "Second";
break;
}
aa = a / b % (b + 1);
if (aa % 2 == 0) {
if (t == 0)
cout << "First";
else
cout << "Second";
break;
}
a = a % b;
t = 1 - t;
}
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
bool win(long long a, long long b) {
if (a == 0)
return false;
else 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;
long long a, b;
int t;
bool win(long long a, long long b) {
if (a == 0 || b == 0) return 0;
if (a > b) swap(a, b);
if (!win(a, b % a)) return 1;
b /= a;
return ((b % (a + 1)) % 2 == 0);
}
int main() {
cin >> t;
for (int i = 1; i <= t; i++) {
cin >> a >> b;
if (win(a, b) == 1) {
printf("First\n");
} else {
printf("Second\n");
}
}
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 == 0) return false;
if (f(a, b % a) == false) return true;
if ((b / a) % (a + 1) % 2 == 0)
return true;
else
return false;
}
int main() {
int t;
long long a, b;
scanf("%d", &t);
while (t--) {
scanf("%I64d%I64d", &a, &b);
if (f(a, b))
printf("First\n");
else
printf("Second\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const long long inf = 1e17 + 7;
bool win(long long a, long long b) { return a != 0; }
bool lose(long long a, long long b) { return a % (b + 1) % 2 == 0; }
void solve() {
long long a, b;
cin >> a >> b;
vector<pair<long long, long long> > c;
while (a != 0 && b != 0) {
if (a < b) swap(a, b);
c.emplace_back(a / b, b);
a = a % b;
}
bool to_win = true;
for (long long i = (long long)c.size() - 1; i >= 0; i--) {
if (to_win) {
to_win = !win(c[i].first, c[i].second);
} else {
to_win = !lose(c[i].first, c[i].second);
}
}
cout << (!to_win ? "First" : "Second") << endl;
}
signed main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
cout.precision(10);
long long t;
cin >> t;
while (t--) solve();
}
|
#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(b % a, a)) return true;
long long df = b - b % a;
if (a % 2)
return df % 2 == 0;
else
return df / a % (a + 1) % 2 == 0;
}
void solve() {
long long a, b;
cin >> a >> b;
if (win(a, b))
cout << "First" << endl;
else
cout << "Second" << endl;
}
int main() {
ios_base::sync_with_stdio(0);
int T;
cin >> T;
for (int _ = 0; _ < (int)(T); _++) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long check(long long a, long long b) {
if (a == 0) {
return 0;
}
if (check(b % a, a)) {
b /= a;
return !((b % (a + 1)) % 2);
}
return 1;
}
int main() {
int N;
scanf("%d", &N);
while (N--) {
long long a, b;
scanf("%lld%lld", &a, &b);
if (a > b) {
swap(a, b);
}
if (check(a, b)) {
printf("First\n");
} else {
printf("Second\n");
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long a, b;
int dfs(long long a, long long b) {
if (a > b) swap(a, b);
if (a == 0) return 0;
if (dfs(b % a, a)) {
b -= b % a;
b /= a;
if (a % 2)
return b % 2 ? 0 : 1;
else
return (b % (a + 1)) % 2 ? 0 : 1;
} else
return 1;
}
void main2() {
scanf("%lld %lld", &a, &b);
if (dfs(a, b))
printf("First\n");
else
printf("Second\n");
}
int TC;
int main() {
scanf("%d", &TC);
while (TC--) main2();
}
|
#include <bits/stdc++.h>
using namespace std;
long long xx[105], yy[105], cnt;
long long gcd(long long x, long long y) {
int res = (y == 0 ? x : gcd(y, x % y));
xx[++cnt] = x;
yy[cnt] = y;
return res;
}
long long ans[105];
bool check(long long a, long long b) {
if (a % 2 == 1) {
return (b / a - 1) % 2;
} else {
if (a >= 1000000000 || b < a * a) {
return !((b / a) % 2);
} else {
long long res = b / a;
long long c1 = (res % (a + 1)) % 2;
long long c2 = res % (a + 1);
return !c1 || (c2 == a);
}
}
}
void solve(long long a, long long b) {
cnt = 0;
gcd(a, b);
ans[1] = 0;
for (int i = 2; i <= cnt; i++) {
if (ans[i - 1] == 0)
ans[i] = 1;
else if (check(yy[i], xx[i] - yy[i - 1]))
ans[i] = 1;
else
ans[i] = 0;
}
if (ans[cnt])
printf("First\n");
else
printf("Second\n");
}
int p = 12;
int biao[100005];
int dabiao(int x) {
if (biao[x] != -1) return biao[x];
if (x < 0) return 0;
int temp = p;
int flag = 0;
while (temp <= x * p) {
if (dabiao(x - temp / p) == 0) {
flag = 1;
break;
}
temp *= p;
}
return biao[x] = flag;
}
int main() {
int n;
cin >> n;
while (n--) {
long long a, b;
cin >> a >> b;
if (a < b) swap(a, b);
if (b == 0)
cout << "Second" << endl;
else if (a % b == 0)
cout << "First" << endl;
else
solve(a, b);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int Tc;
long long a, b;
bool win(long long x, long long y) {
if (!x || !y) return 0;
if (x > y) swap(x, y);
if (!win(x, y % x)) return 1;
return y / x % (x + 1) % 2 == 0;
}
int main() {
cin >> Tc;
while (Tc--) {
cin >> a >> b;
if (win(a, b))
puts("First");
else
puts("Second");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool PLAY(long long x, long long y) {
if (x > y) {
long long t = x;
x = y;
y = t;
}
if (x == 0)
return false;
else if (PLAY(x, y % x) == false)
return true;
else
return ((y / x) % (x + 1) % 2 == 0);
}
int main() {
long long n, a, b;
cin >> n;
while (n--) {
cin >> a >> b;
if (PLAY(a, b) == true)
cout << "First" << endl;
else
cout << "Second" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int BASE = 27;
bool solve(long long a, long long b) {
if (a > b) swap(a, b);
if (a == 0) return false;
bool win = false;
if (!solve(a, b % a)) win = true;
long long g = b / a;
if (a % 2 == 1 && g % 2 == 0) win = true;
if (a % 2 == 0 && (g % (a + 1)) % 2 == 0) win = true;
return win;
}
int t;
long long a, b;
int main() {
cin >> t;
while (t--) {
cin >> a >> b;
puts(solve(a, b) ? "First" : "Second");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long T;
bool solve(long long n, long long m) {
if (n > m) swap(n, m);
if (!n) return 0;
bool f = solve(m % n, n);
if (!f) return 1;
long long num = m / n;
if (n % 2 == 1) {
if (f)
return !(num & 1);
else
return num & 1;
} else {
num %= (n + 1);
if (f)
return !(num & 1);
else
return num & 1;
}
}
signed main() {
cin >> T;
while (T--) {
cin >> n >> m;
if (solve(n, m))
puts("First");
else
puts("Second");
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long T, a, b;
bool solve(long long a, long long b) {
if (!a || !b) return false;
if (!solve(b % a, a)) return true;
long long k = (b / a - 1) % (a + 1);
return k & 1 || k == a;
}
int main() {
scanf("%d", &T);
while (T--) {
scanf("%lld%lld", &a, &b);
if (a > b) swap(a, b);
puts(solve(a, b) ? "First" : "Second");
}
return 0;
}
|
#include <bits/stdc++.h>
long long w(long long a, long long b) {
return b ? !w(b, a % b) | 1 - a / b % (b + 1) % 2 : 0;
}
int main() {
long long a, b, t;
for (std::cin >> t; t--;)
std::cin >> a >> b, a < b ? a ^= b ^= a ^= b : 0,
puts(w(a, b) ? "First" : "Second");
}
|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
int st[105][105];
void stup() {
for (int i = 1; i <= int(105 - 1); i++) {
st[i][0] = st[0][i] = -1;
}
for (int i = 1; i <= int(105 - 1); i++) {
for (int j = 1; j <= int(105 - 1); j++) {
if (i >= j) {
st[i][j] = -1;
if (st[i % j][j] == -1) st[i][j] = 1;
int a = j;
while (a <= i) {
if (st[i - a][j] == -1) st[i][j] = 1;
a *= j;
if (j == 1) break;
}
} else {
st[i][j] = -1;
if (st[i][j % i] == -1) st[i][j] = 1;
int a = i;
while (a <= j) {
if (st[i][j - a] == -1) st[i][j] = 1;
a *= i;
if (i == 1) break;
}
}
}
}
}
int calc(long long a, long long b) {
if (a == 0) return -1;
if (a == 1) return 1;
if (calc(b % a, a) == -1) return 1;
b /= a;
if (a % 2 == 1) {
if (b & 1) return -1;
return 1;
}
b = (b - 1) % (a + 1);
if (b == a || (b % 2 == 1)) return 1;
return -1;
}
int main() {
int t;
cin >> t;
for (int it = 0; it < int(t); it++) {
long long a, b;
cin >> a >> b;
if (a > b) swap(a, b);
if (calc(a, b) == 1)
cout << "First\n";
else
cout << "Second\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 250;
const double eps = 1e-9;
const int oo = 1000000000;
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
int main() {
int T;
scanf("%d", &T);
while (T--) {
long long p, q;
int ac = 1;
pair<long long, long long> pro[N];
bool f[N];
cin >> p >> q;
if (p + q == 0) {
puts("Second");
continue;
}
if (p < q) {
swap(p, q);
}
pro[0] = make_pair(p, q);
while (pro[ac - 1].second) {
pro[ac] =
make_pair(pro[ac - 1].second, pro[ac - 1].first % pro[ac - 1].second);
ac++;
}
f[ac - 1] = false;
for (int i = ac - 2; i >= 0; --i) {
if (!f[i + 1]) {
f[i] = true;
} else {
long long fac = (pro[i].first - pro[i + 1].second) / pro[i].second;
if (pro[i].second & 1) {
f[i] = ((fac & 1) ^ 1);
} else {
f[i] = (((fac % (pro[i].second + 1)) & 1) ^ 1);
}
}
}
if (f[0]) {
puts("First");
} else {
puts("Second");
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
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() {
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
long long a, b;
cin >> a >> b;
if (win(min(a, b), max(a, b)))
cout << "First\n";
else
cout << "Second\n";
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma warning(disable : 4244 4267 4018 4996 4800)
using namespace std;
istream& in = cin;
ostream& out = cout;
bool solve(long long a, long long b) {
if (a < b) swap(a, b);
if (b == 0) return false;
if (b == 1) return true;
if (!solve(b, a % b)) return true;
a = (a / b) - 1;
long long t = a % (b + 1);
return ((t & 1) || t == b);
}
int main() {
int t;
in >> t;
for (int i = 0; i < t; ++i) {
long long a, b;
in >> a >> b;
out << (solve(a, b) ? "First" : "Second") << '\n';
}
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;
return !(((b / a) % (a + 1)) % 2);
}
int main() {
ios::sync_with_stdio(false);
int i, n;
long long a, b;
cin >> n;
for ((i) = 0; (i) < (n); (i)++) {
cin >> a >> b;
if (a > b) swap(a, b);
cout << (win(a, b) ? "First" : "Second") << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxN = 10000 + 10;
int N;
bool solve(long long a, long long b) {
if (a == 0 || b == 0) return false;
if (!solve(b % a, a)) return true;
return (b / a) % (a + 1) % 2 == 0;
}
int main() {
scanf("%d", &N);
for (int i = 0; i < N; ++i) {
long long a, b;
scanf("%I64d %I64d", &a, &b);
if (solve((a < b ? a : b), (a > b ? a : b)))
printf("First\n");
else
printf("Second\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int T;
inline bool Calc(long long a, long long b) {
if (!a) return 0;
if (!Calc(b % a, a)) return 1;
return (((b / a) % (a + 1) & 1) == 0);
}
int main() {
long long a, b;
for (scanf("%d", &T); T--;) {
cin >> a >> b;
if (Calc(min(a, b), max(a, b)))
printf("First\n");
else
printf("Second\n");
}
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) {
if (a == 0)
return false;
else if ((b / a) % (a + 1) % 2 == 0)
return true;
else
return !first(b % a, a);
}
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;
int f[110];
bool wins(long long a, long long b) {
if (a == 0) return false;
if (!wins(b % a, a)) return true;
long long k = b / a - 1;
if (a & 1) return k & 1;
k %= (a + 1);
if (k == a) return true;
return k & 1;
}
int main() {
int tCnt;
for (cin >> tCnt; tCnt; tCnt--) {
long long a, b;
cin >> a >> b;
if (a > b) swap(a, b);
cout << (wins(a, b) ? "First" : "Second") << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int T, i, j, k;
long long a, b;
bool calc(long long a, long long b) {
if (a > b) swap(a, b);
if (a == 0) return false;
bool f = calc(a, b % a);
if (!f) return true;
if (a % 2) {
if ((b / a) % 2)
return false;
else
return true;
} else {
if (((b / a) % (a + 1)) % 2 == 0)
return true;
else
return false;
}
}
int main() {
scanf("%d", &T);
for (; T; --T) {
scanf("%I64d%I64d", &a, &b);
if (calc(a, b))
printf("First\n");
else
printf("Second\n");
}
}
|
#include <bits/stdc++.h>
long long x, y, t;
using namespace std;
int F(long long x, long long y) {
return x < y ? F(y, x) : y && (!F(x % y, y) || 1 - x / y % (y + 1) % 2);
}
int main() {
cin >> t;
for (; t; t--) cin >> x >> y, puts(F(x, y) ? "First" : "Second");
}
|
#include <bits/stdc++.h>
using namespace std;
struct Sta {
bool f0, f1, f2, f3;
};
Sta dfs(long long A, long long B) {
if (A > B) return dfs(B, A);
if (A == 0) return (Sta){0, 0, 0, 1};
Sta d = dfs(B % A, A), ans;
long long k = B / A;
bool p = !((k % (A + 1)) & 1);
if (p) {
ans.f0 = 1;
ans.f1 = 0;
ans.f2 = 0;
ans.f3 = 0;
} else {
ans.f0 = d.f1;
ans.f1 = d.f0;
ans.f2 = d.f3;
ans.f3 = d.f2;
}
return ans;
}
int T;
long long A, B;
int main() {
scanf("%d", &T);
while (T--) {
scanf("%lld%lld", &A, &B);
Sta ans = dfs(A, B);
printf("%s\n", (ans.f0 || ans.f2) ? "First" : "Second");
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int INF = (int)1E9;
const long long INF64 = (long long)1E18;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;
bool solve(long long a, long long b) {
if (min(a, b) == 0) return false;
if (a > b) return solve(b, a);
if (!solve(b % a, a)) return true;
b = (b / a) - 1;
if (a % 2 == 1) {
if (b % 2 == 1) return true;
return false;
} else {
if ((b % (a + 1)) % 2 == 1 || (b % (a + 1)) == a) return true;
return false;
}
}
int main() {
int tests;
cin >> tests;
for (int test = 0; test < (int)(tests); test++) {
long long a, b;
cin >> a >> b;
if (solve(a, b))
printf("First\n");
else
printf("Second\n");
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:25600000")
using namespace std;
bool win(long long a, long long b) {
if (a < b) swap(a, b);
if (b == 0) return false;
if (a % b == 0) return true;
if (!win(a % b, b)) return true;
if (b % 2) {
long long k = a / b;
if (k % 2 == 0) return true;
} else {
long long k = a / b;
k %= (b + 1);
if (k == 0) return true;
if (k % 2 == 0) return true;
}
return false;
}
int main() {
int tests;
cin >> tests;
for (long long TEST = 0; TEST < tests; TEST++) {
long long a, b;
cin >> a >> b;
win(a, b) ? cout << "First\n" : cout << "Second\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
bool Solve2(long long x, long long y) {
if (y % 2)
return 1 - x % 2;
else
return 1 - (x % (y + 1)) % 2;
}
bool Solve(long long x, long long y) {
if (x < y) swap(x, y);
if (y == 0) return 0;
if (x % y == 0) return 1;
if (!Solve(x % y, y)) return 1;
return Solve2(x / y, y);
}
int main() {
int t;
cin >> t;
while (t--) {
long long x, y;
cin >> x >> y;
cout << (Solve(x, y) ? "First" : "Second") << endl;
};
return 0;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long calc(long long a, long long b) {
if (a == 0) return 0;
if ((b / a) % (a + 1) % 2 == 0) return 1;
if (!calc(b % a, a)) return 1;
return 0;
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
long long a, b;
scanf("%I64d %I64d", &a, &b);
if (a > b) swap(a, b);
if (calc(a, b))
puts("First");
else
puts("Second");
}
}
|
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
int get(long long i, long long j) {
if (i == 0 || j == 0) return 0;
if (i == 1 || j == 1) return 1;
if (i > j) swap(i, j);
if (j / i >= i + 1) {
j %= i * (i + 1LL);
}
if (j <= i) return 1;
j %= 2 * i;
if (j >= i + i) return 1;
if (j <= i) return 1;
return 1 - get(j - i, i);
}
int main() {
int ntest;
scanf("%d", &ntest);
while (ntest--) {
long long a, b;
cin >> a >> b;
if (get(a, b))
puts("First");
else
puts("Second");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int Tc;
long long a, b, c;
bool turn;
int main() {
scanf("%d", &Tc);
while (Tc--) {
scanf("%I64d%I64d", &a, &b);
turn = 0;
while (1) {
if (a > b) swap(a, b);
if (!a) {
turn ^= 1;
{
if (!turn) puts("First");
if (turn) puts("Second");
break;
}
}
c = b % a;
b /= a;
if (a % 2) {
if (b % 2 == 0) {
if (!turn) puts("First");
if (turn) puts("Second");
break;
}
{
b = c;
turn ^= 1;
continue;
}
}
if (a >= b) {
if (b % 2 == 0) {
if (!turn) puts("First");
if (turn) puts("Second");
break;
}
{
b = c;
turn ^= 1;
continue;
}
}
long long squ = b % (a + 1);
if (squ % 2) {
b = c;
turn ^= 1;
continue;
} else {
if (!turn) puts("First");
if (turn) puts("Second");
break;
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T checkmin(T &a, T b) {
return (a < b) ? a : a = b;
}
template <class T>
inline T checkmax(T &a, T b) {
return (a > b) ? a : a = b;
}
template <class T>
T GCD(T a, T b) {
if (a < 0) return GCD(-a, b);
if (b < 0) return GCD(a, -b);
return (a == 0) ? b : GCD(b % a, a);
}
template <class T>
T LCM(T a, T b) {
if (a < 0) return LCM(-a, b);
if (b < 0) return LCM(a, -b);
return (a == 0 || b == 0) ? 0 : a / GCD(a, b) * b;
}
template <class T>
T ExtGCD(T a, T b, T &x, T &y) {
if (a < 0) {
T c = ExtGCD(-a, b, x, y);
x = -x;
return c;
}
if (b < 0) {
T c = ExtGCD(a, -b, x, y);
y = -y;
return c;
}
if (a == 0) {
x = 0, y = 1;
return b;
} else {
T c = ExtGCD(b % a, a, y, x);
x -= b / a * y;
return c;
}
}
template <class T>
inline T sqr(T X) {
return X * X;
}
namespace Poor {
bool f(long long a, long long b) {
if (a > b) swap(a, b);
if (a == 0) return 0;
if (a == 1) return 1;
long long t = b / a;
vector<long long> list;
while (t > 0) {
list.push_back(t % a);
t /= a;
}
if (list.size() == 1) {
if (list[0] % 2 == 0) return 1;
return !f(b % a, a);
}
if (a % 2 == 0) {
if (!f(b % a, a)) return 1;
return (((b / a) % (a + 1)) % 2 == 0);
}
if ((b / a) % 2 == 0) return 1;
return !f(b % a, a);
}
void Solve() {
long long a, b;
cin >> a >> b;
puts(f(a, b) ? "First" : "Second");
}
void Run() {
int TestCase;
cin >> TestCase;
for (int i = 1; i <= TestCase; ++i) Solve();
}
} // namespace Poor
int main() {
Poor::Run();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double C = 0.57721566490153286060651209;
const double pi = acos(-1.0);
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
int SG(long long a, long long b) {
if (a == 0 || b == 0) return 0;
if (SG(b % a, a)) {
b /= a;
return !(b % (a + 1) & 1);
}
return 1;
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
long long a, b;
cin >> a >> b;
int num = 1;
if (a > b) swap(a, b);
if (SG(a, b) == 0)
cout << "Second" << endl;
else
cout << "First" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (ch < '0' || '9' < ch) {
if (ch == '-') f = -1;
ch = getchar();
}
while ('0' <= ch && ch <= '9')
x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
return x * f;
}
long long t, x, y, z;
long long dfs(long long x, long long y) {
if (x == 0 || y == 0) return 0;
if (x < y) swap(x, y);
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() {
cin >> t;
for (long long i = 1; i <= t; i++) {
cin >> x >> y;
if (dfs(x, y))
printf("First\n");
else
printf("Second\n");
}
}
|
#include <bits/stdc++.h>
template <typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
return true;
}
constexpr bool hasBegin(...) { return false; }
template <typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;
template <class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
return os << p.first << " " << p.second;
}
template <class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os,
Container const &x) {
bool first = true;
for (auto &y : x) {
if (first) {
first = false;
} else {
os << " ";
}
os << y;
}
return os;
}
using namespace std;
class CWizardsAndNumbers {
void solve(int testNumber, istream &in, ostream &out) {
long long a, b;
in >> a >> b;
if (a < b) {
swap(a, b);
}
bool res = f(a, b);
out << (res ? "First" : "Second") << "\n";
}
bool f(long long a, long long b) {
if (b == 0) {
return false;
}
bool next = f(b, a % b);
if (not next) {
return true;
}
long long d = (a - a % b) / b;
if (b % 2) {
return d % 2 == 0;
}
return d % (b + 1) % 2 == 0;
}
public:
void solve(std::istream &in, std::ostream &out) {
int t;
in >> t;
for (int i = 1; i <= t; ++i) {
solve(i, in, out);
}
}
void setup() {}
};
int main() {
std::ios_base::sync_with_stdio(false);
CWizardsAndNumbers solver;
solver.setup();
std::istream &in(std::cin);
std::ostream &out(std::cout);
in.tie(nullptr);
out << std::fixed;
out.precision(20);
solver.solve(in, out);
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) {
if (a == 0)
return false;
else if (first(b % a, a))
return (b / a) % (a + 1) % 2 == 0;
else
return true;
}
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 ok(long long x, long long y) {
if (x > y) swap(x, y);
if (x == 0) return 0;
if (!ok(x, y % x)) return 1;
long long d = y / x;
return ((d % (x + 1LL)) % 2 + 2) % 2 == 0;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
long long x, y;
cin >> x >> y;
puts(ok(x, y) ? "First" : "Second");
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long check(long long a, long long b) {
if (a == 0) return 0;
if (check(b % a, a)) {
b = b / a;
return !(b % (a + 1) & 1);
}
return 1;
}
int main() {
long long a, b, t;
scanf("%lld", &t);
while (t--) {
cin >> a >> b;
if (a > b) swap(a, b);
if (check(a, b))
puts("First");
else
puts("Second");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
map<pair<long long, long long>, bool> f;
long long a, b, Test;
bool Check(long long x, long long a) {
if (!x) return false;
return (x % (a + 1)) % 2 == 0;
}
bool Dp(long long a, long long b) {
if (!a) return false;
pair<long long, long long> p = make_pair(a, b);
if (f.find(p) != f.end()) return f[p];
bool g = Dp(b % a, a);
if (!g)
f[p] = true;
else {
int cnt = 0;
long long x = b / a;
if (Check(x, a))
f[p] = true;
else
f[p] = false;
}
return f[p];
}
int main() {
scanf("%d", &Test);
f.clear();
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;
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;
int t;
bool get(long long a, long long b) {
if (a == 0LL || b == 0LL) {
return 0;
}
if (a > b) {
swap(a, b);
}
if (!get(a, b % a)) {
return 1;
}
if (a % 2LL == 1LL) {
if ((b / a - 1LL) % 2LL == 1LL) {
return 1;
}
} else {
if ((b / a - 1LL) % (a + 1LL) == a ||
((b / a - 1LL) % (a + 1LL)) % 2LL == 1LL) {
return 1;
}
}
return 0;
}
int main() {
cin >> t;
for (int k = 0; k < t; k++) {
long long a, b;
cin >> a >> b;
if (get(a, b)) {
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 == 0) {
return false;
}
if (a == 1) {
return true;
}
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>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const double pi = 3.1415926535897932384626433832795;
double eps = 1e-9;
char ch[1 << 20];
inline string gs() {
scanf("%s", ch);
return string(ch);
}
inline string gl() {
gets(ch);
return string(ch);
}
inline int gi() {
int x;
scanf("%d", &x);
return x;
}
void error(bool x) {
if (x) {
fprintf(stderr, "ERROR\n");
int ttt = 0;
cout << 7 / ttt;
}
}
template <class T>
T gcd(T a, T b) {
return (!a) ? b : gcd(b % a, a);
}
int mod = 1000000007;
inline int ADD(int a, int b) { return (a + b >= mod) ? a + b - mod : a + b; }
inline int SUB(int a, int b) { return (a - b < 0) ? a - b + mod : a - b; }
inline int MUL(int a, int b) { return 1ll * a * b % mod; }
inline int POW(int a, int n) {
int r = 1;
while (n) {
if (n & 1) r = MUL(r, a);
n >>= 1;
a = MUL(a, a);
}
return r;
}
const int MATRIX_SIZE = 11;
typedef int matrix[MATRIX_SIZE][MATRIX_SIZE];
void MMUL(matrix &a, matrix &b) {
matrix c;
for (int i = (0), _b(MATRIX_SIZE); i < _b; ++i)
for (int j = (0), _b(MATRIX_SIZE); j < _b; ++j) c[i][j] = 0;
for (int i = (0), _b(MATRIX_SIZE); i < _b; ++i)
for (int j = (0), _b(MATRIX_SIZE); j < _b; ++j) {
for (int k = (0), _b(MATRIX_SIZE); k < _b; ++k)
c[i][j] = ADD(c[i][j], MUL(a[i][k], b[k][j]));
}
for (int i = (0), _b(MATRIX_SIZE); i < _b; ++i)
for (int j = (0), _b(MATRIX_SIZE); j < _b; ++j) a[i][j] = c[i][j];
}
int solve(long long a, long long b) {
if (a > b) swap(a, b);
if (a == 0) {
return 0;
} else {
int win = solve(b % a, a);
if (win == 0) return 1;
long long n = b / a;
if (a % 2LL == 1) {
if (n % 2LL == 1)
return 0;
else
return 1;
} else {
if ((n % (a + 1LL)) % 2LL == 0)
return 1;
else
return 0;
}
}
}
int main(int argn, char **argv) {
int tn = gi();
while (tn--) {
long long a;
long long b;
cin >> a >> b;
if (solve(a, b))
printf("First\n");
else
printf("Second\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
double DP[201][201][201];
bool brut(long long A, long long B) {
if (B > A) return brut(B, A);
if (B == 0) return false;
bool result = false;
if (!brut(B, A % B)) return true;
long long temp = 1;
while (A / temp >= B) {
temp *= B;
if (!brut(A - temp, B)) return true;
}
return false;
}
bool get(long long A, long long B) {
if (B > A) return get(B, A);
if (B == 0) return false;
bool temp = get(B, A % B);
if (!temp) return true;
A -= A % B;
A /= B;
return ((A % (B + 1)) % 2 == 0);
}
int main() {
int T;
cin >> T;
for (int t = 0; t < (T); ++t) {
long long A, B;
cin >> A >> B;
printf(get(A, B) ? "First\n" : "Second\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
int t;
long long a, b;
bool solve(long long a, long long b) {
if (a == 0 || b == 0) return 0;
if (a > b) return solve(b, a);
if (!solve(a, b % a)) return 1;
long long cur = b / a;
if (a & 1) return cur % 2 == 0;
return (cur % (a + 1)) % 2 == 0;
}
int main() {
cin >> t;
while (t--) {
cin >> a >> b;
if (solve(a, b))
cout << "First" << endl;
else
cout << "Second" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int test;
long long a, b;
inline 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;
int n;
int solve(long long a, long long b) {
if (a < b) swap(a, b);
if (a == 0 || b == 0) return 0;
if (a % b == 0) return 1;
if (solve(b, a % b) == 0) return 1;
return ((a / b) % (b + 1) + 1) % 2;
}
int main() {
scanf("%d", &n);
long long a, b;
int flag;
for (int i = 1; i <= n; i++) {
scanf("%I64d %I64d", &a, &b);
flag = solve(a, b);
if (flag)
printf("First\n");
else
printf("Second\n");
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target( \
"sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int MOD = 1000000007;
const int UNDEF = -1;
const int INF = 1 << 30;
template <typename T>
inline bool chkmax(T& aa, T bb) {
return aa < bb ? aa = bb, true : false;
}
template <typename T>
inline bool chkmin(T& aa, T bb) {
return aa > bb ? aa = bb, true : false;
}
int rint();
char rch();
long long rlong();
bool fast(long long a, long long x) {
if (a & 1)
return (x & 1) ^ 1;
else {
x %= (a + 1);
return (x & 1) ^ 1;
}
}
bool f(long long a, long long b) {
if (a == 0 || b == 0) return false;
if (a > b) swap(a, b);
bool nextwin = f(b % a, a);
if (!nextwin) return true;
return fast(a, b / a);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
for (int i = 0; i < t; i++) {
long long a, b;
cin >> a >> b;
bool ans = f(a, b);
if (ans)
printf("First\n");
else
printf("Second\n");
}
}
static char stdinBuffer[1024];
static char* stdinDataEnd = stdinBuffer + sizeof(stdinBuffer);
static const char* stdinPos = stdinDataEnd;
void readAhead(size_t amount) {
size_t remaining = stdinDataEnd - stdinPos;
if (remaining < amount) {
memmove(stdinBuffer, stdinPos, remaining);
size_t sz = fread(stdinBuffer + remaining, 1,
sizeof(stdinBuffer) - remaining, stdin);
stdinPos = stdinBuffer;
stdinDataEnd = stdinBuffer + remaining + sz;
if (stdinDataEnd != stdinBuffer + sizeof(stdinBuffer)) *stdinDataEnd = 0;
}
}
int rint() {
readAhead(16);
int x = 0;
bool neg = false;
while (*stdinPos == ' ' || *stdinPos == '\n') ++stdinPos;
if (*stdinPos == '-') {
++stdinPos;
neg = true;
}
while (*stdinPos >= '0' && *stdinPos <= '9') {
x *= 10;
x += *stdinPos - '0';
++stdinPos;
}
return neg ? -x : x;
}
char rch() {
readAhead(16);
while (*stdinPos == ' ' || *stdinPos == '\n') ++stdinPos;
char ans = *stdinPos;
++stdinPos;
return ans;
}
long long rlong() {
readAhead(32);
long long x = 0;
bool neg = false;
while (*stdinPos == ' ' || *stdinPos == '\n') ++stdinPos;
if (*stdinPos == '-') {
++stdinPos;
neg = true;
}
while (*stdinPos >= '0' && *stdinPos <= '9') {
x *= 10;
x += *stdinPos - '0';
++stdinPos;
}
return neg ? -x : x;
}
|
#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 0;
if (!solve(b % a, a)) return 1;
return ((b / a) % (a + 1)) & 1 ^ 1;
}
int main() {
int T;
cin >> T;
while (T--) {
long long a, b;
cin >> a >> b;
cout << (solve(a, b) ? "First" : "Second") << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int sol(long long a, long long b) {
if (a > b) swap(a, b);
if (a == 0 || b == 0) return 0;
if (b % a == 0) return 1;
int ret = !sol(a, b % a);
if (ret) return 1;
b = b / a;
if (a & 1) return b % 2 == 0;
b--;
return b % (a + 1) == a || b % (a + 1) % 2 != 0;
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
long long a, b;
scanf("%I64d%I64d", &a, &b);
puts(sol(a, b) ? "First" : "Second");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline bool solve(long long a, long long b) {
if (b == 0) return 0;
if (!solve(b, a % b)) return 1;
long long x = 0;
a /= b;
if (b % 2 == 1) return !(a % 2);
a--;
a %= (b + 1);
if (a == b) return 1;
return a % 2;
}
int dp[5000];
int dp2[5000];
int main() {
int t, i, j;
dp[0] = 1;
int x = 11;
for (i = 1; i < 5000; i++) {
for (j = 1; j <= x && j <= i; j *= x)
if (dp[i - j] == 0) break;
if (j <= i && j <= x) {
dp[i] = 1;
} else {
dp[i] = 0;
}
}
dp2[0] = 1;
for (i = 1; i < 5000; i++) {
for (j = 1; j <= i; j *= x)
if (dp2[i - j] == 0) break;
if (j <= i) {
dp2[i] = 1;
} else {
dp2[i] = 0;
}
if (dp2[i] != dp[i]) printf("%d\t", i);
}
scanf("%d", &t);
while (t--) {
long long a, b;
scanf("%I64d%I64d", &a, &b);
if (a < b) swap(a, b);
puts(solve(a, b) ? "First" : "Second");
}
}
|
#include <bits/stdc++.h>
using namespace std;
bool go(long long int A, long long int B) {
if (A < B)
return go(B, A);
else if (B == 0)
return false;
else if (A % B == 0)
return true;
else if (!go(B, A % B))
return true;
else {
long long int K = A / B;
return (K % (B + 1)) % 2 == 0;
}
}
int main() {
int T;
cin >> T;
while (T--) {
long long int A, B;
cin >> A >> B;
if (go(A, B))
puts("First");
else
puts("Second");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int win(long long a, long long b) {
if (!a || !b) return 0;
long long x = win(b % a, a);
if (!x) return 1;
b /= a;
if (a & 1) return b % 2 == 0;
long long z = b % (a + 1);
return z % 2 == 0;
}
int main() {
int test;
cin >> test;
while (test--) {
long long a, b;
cin >> a >> b;
if (a > b) swap(a, b);
puts(win(a, b) ? "First" : "Second");
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX = int(1e5) + 10;
int CHAR;
inline void eat() {
do {
CHAR = getchar();
} while (CHAR == ' ' || CHAR == '\n' || CHAR == '\t');
}
inline long long getnumber() {
eat();
long long ret = 0;
while (isdigit(CHAR)) {
ret = 10 * ret + CHAR - 48;
CHAR = getchar();
}
return ret;
}
inline void getstring(char *str) {
eat();
int cc = 0;
while (isalpha(CHAR)) {
str[cc++] = CHAR;
CHAR = getchar();
}
str[cc] = '\0';
}
bool win(long long a, long long b) {
if (a > b) swap(a, b);
if (a == 0) return false;
if (!win(b % a, a)) return true;
long long x = b / a;
return x % (a + 1) % 2 == 0;
}
int main() {
for (int test = getnumber(); test; test--) {
long long a = getnumber(), b = getnumber();
if (win(a, b))
cout << "First\n";
else
cout << "Second\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool judge(long long a, long long b) {
if (a == 0 || b == 0) return false;
if (judge(b, a % b)) {
if ((a / b % (b + 1)) % 2 == 0)
return true;
else
return false;
}
return true;
}
int main() {
long long a, b, t;
cin >> t;
while (t--) {
cin >> a >> b;
if (a < b) swap(a, b);
if (judge(a, b)) {
cout << "First" << endl;
} else {
cout << "Second" << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int win(long long a, long long b) {
if (a > b) swap(a, b);
if (!a) return 0;
if (!(b % a)) return 1;
long long X = b / a - 1;
if (a % 2) return (X % 2) || (!win(b % a, a));
X = X % (a + 1);
return (X % 2) || (X == a) || (!win(b % a, a));
}
int main() {
int T;
long long a, b;
scanf("%d", &T);
for (int t = 0; t < (T); ++t) {
cin >> a >> b;
printf("%s\n", win(a, b) ? "First" : "Second");
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long Q, a, b;
long long dfs(long long a, long long b) {
if (a > b) swap(a, b);
if (a == 0) return 0;
if (dfs(a, b % a) == 0) return 1;
long long k = (b / a) % (a + 1);
return (k % 2 == 0 ? 1 : 0);
}
signed main() {
cin >> Q;
while (Q--) {
scanf("%lld%lld", &a, &b);
if (a > b) swap(a, b);
if (a == 0)
puts("Second");
else if (b % a == 0)
puts("First");
else
puts(dfs(a, b) ? "First" : "Second");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool calc(long long a, long long b) {
if (!a || !b) return 0;
if (a > b) swap(a, b);
if (!calc(b % a, a)) return 1;
long long c = b / a;
if (a & 1)
return c % 2 == 0;
else
return c % (a + 1) % 2 == 0;
}
int main() {
int tst;
cin >> tst;
long long A, B;
while (tst--) {
cin >> A >> B;
cout << (calc(A, B) ? "First" : "Second") << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
bool good(int64_t a, int64_t b) {
if (a == 0) return false;
if (!good(b % a, a)) return true;
int64_t c = b / a;
return (c % (a + 1)) % 2 == 0;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
int t;
cin >> t;
while (t--) {
int64_t a, b;
cin >> a >> b;
if (a > b) swap(a, b);
cout << (good(a, b) ? "First" : "Second") << "\n";
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.