Who is better?
题目看懂了就很简单,首先是给你a和b,
看能不能找到这样一个n满足上述关系。
用中国剩余定理来求。
如果找不到就是
"Tankernb!"
找到的话就用 斐波那契博弈论 的结论。
石头数 为 斐波那契数的话 先手 必败。
思路是先算n,然后计算斐波那契数。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <stack>
#include <vector>
#include <typeinfo>
#include <set>
using namespace std;
#define ll long long
typedef long double ld;
#define INF 0x3f3f3f3f
#define ms(a, b) memset((a), (b), sizeof (a))
#define readfile(a) freopen((a),"r",stdin);
//#define max(a,b) a = ((a) > (b) ? (a):(b))
typedef long long LL;
int n;
long long a[100005], b[100005];
long long exgcd(long long a, long b, long long &x, long long &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
long long gcd = exgcd(b, a%b, x, y);
ll t = x;
x = y;
y = t - a / b * y;
return gcd;
}
long long cheng(long long x, long long y, long long z)//快速乘
{
long long t = 0;
x = (x%z + z) % z;//快速乘一定要加这两句话,因为x可能是负数
y = (y%z + z) % z;
while (x > 0) {
if (x % 2 == 1) t = (t + y) % z;
y = y * 2 % z;
x /= 2;
}
return t;
}
long long excrt()
{
long long x = b[1], x1, x2, m = a[1];
for (int i = 2; i <= n; i++) {
long long z = ((b[i] - x) % a[i] + a[i]) % a[i];//为避免溢出,要对a[i]取模
long long gcd = exgcd(m, a[i], x1, x2);//求m*x1+a[i]*x2=gcd(m,a[i])的一组解,gcd=gcd(m,a[i])
if (z%gcd != 0) return 0;//说明无解
x1 = cheng(x1, z / gcd, a[i]);//x1=x1*z/gcd,同时调整x1为最小正数解
x = cheng(m, x1, m / gcd * a[i]) + x;//构造新的同余方程
m = m / gcd * a[i];
x = x % m;//上上行加了x之后还要取一次模
}
return x;//x就是最终是答案
}
void fun(ll now){
ll p1 = 0,p2 = 1,s = 0;
while(s < now)
{
s = p1 + p2;
p1 = p2;
p2 = s;
}
if(s == now)puts("Lbnb!");
else puts("Zgxnb!");
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i++){
scanf("%lld %lld", &a[i], &b[i]);
}
ll now = excrt();
if(!now) puts("Tankernb!");
else
fun(now);
return 0;
}