The Preliminary Contest for ICPC Asia Xuzhou 2019
A. Who is better?
本题为典型的斐波那契博弈,使用拓展中国定理求出n后打表即可
引用自:
/*9.7徐州 A*/
#pragma GCC optimize(3)
#pragma comment(linker,"/STACK:102400000,1024000")
#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable:4996)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define Maxn 80
/*中国剩余定理板子*/
void exgcd(ll a, ll b, ll& g, ll& x, ll& y)
{
if (b == 0)
{
g = a;
x = 1;
y = 0;
return;
}
exgcd(b, a % b, g, y, x);
y -= (a / b) * x;
}
bool flag = false;
ll a1, a2, n1, n2;
void china()
{
ll d = a2 - a1;
ll g, x, y;
exgcd(n1, n2, g, x, y);
if (g != 0 && d % g == 0)
{
x = ((x * d / g) % (n2 / g) + (n2 / g)) % (n2 / g);
a1 = x * n1 + a1;
n1 = (n1 * n2) / g;
}
else
flag = true;
}
int n;
long long as[100001];
long long ns[100001];
ll realchina()
{
a1 = as[0];
n1 = ns[0];
for (ll i = 1; i < n; i++)
{
a2 = as[i];
n2 = ns[i];
china();
if (flag)
return -1;
}
return a1;
}
ll fib[Maxn] = { 1,1 };
signed main()
{
for (ll i = 2; i < Maxn; i++)
{
fib[i] = fib[i - 1] + fib[i - 2];
}
cin >> n ;
flag = false;
for (ll i = 0; i < n; i++)
cin >> ns[i] >> as[i];
ll ans = realchina();
if (ans == -1)
{
cout << "Tankernb!" << endl;
return 0;
}
//cout << fib[Maxn - 1] << endl;
bool ok = 0;
for (ll i = 1; i < Maxn; i++)
{
if (fib[i] == ans)
ok = 1;
}
if (ok)
cout << "Lbnb!" << endl;
else
cout << "Zgxnb!" << endl;
}