天天看點

The Preliminary Contest for ICPC Asia Xuzhou 2019 A . Who is better?

After Asgard was destroyed, tanker brought his soldiers to earth, and at the same time took on the important task of protecting the peace of the earth. The best two solders were lb and zgx, were very capable, but they always disliked each other. However, one day they encountered a group of foreign invaders (many, but how many only tanker knew). They were all strong enough to destroy the enemy easily. But they found it too boring, so they agreed to follow some rules to deal with the invaders by taking turns, and if one of them had no enemies when it was his turn, he would later admit that the other man was better.

The rules are as follows:

  • zgx takes the first turn. But he cannot destroy all the enemies at the first time;
  • after that, the number of enemies that can be destroyed at a time is between 111 enemy and 222 times the number of enemies that the former has just destroyed (including 111 enemy and 222 times the number of enemies that the opponent has just destroyed).
  • the winner is the one who agrees to destroy the last enemy. Both zgx and lb are smart, so they only perform actions that are best for them.

To ensure fairness, they found their leader, tanker, to judge, but tanker just wanted people to say he was great, so he didn't want them to decide easily, so he hid the number of intruders in a question:

  • there are kkk sets of integers aaa and bbb such that nnn ≡ bbb (mod aaa).
  • nnn is the minimum positive integer solution satisfying the kkk groups aaa and bbb.

Input

In the first line, input kkk, and on lines 222 to k+1k + 1k+1, input kkk groups aaa and bbb.

Output

If lb wins, output "

Lbnb!

", if zgx wins, output "

Zgxnb!

", if they can't solve, (nnn does not exist) , output "

Tankernb!

" .

Note:

k≤10k\le 10k≤10 ,1< n≤1015n \le 10^{15}n≤1015

For the sample, n=8n=8n=8,because 8%5=38\%5=38%5=3, 8%3=2 8 \%3=28%3=2 and 888 is the smallest possible integer that is fit the requirement.

樣例輸入

2
5 3
3 2      

樣例輸出

Lbnb!      

思路:這題前面一看就是斐波那契博弈,後面就是擴充中國剩餘定理,然後就用map存一下小于1e15的斐波那契數,然後就擴充中國剩餘定理随便搞了

#include<stdio.h>
#include<map>
using namespace std;
#define ll long long int
map<ll,ll>vis;
ll fab[100000];
ll a[15],b[15];
ll gcd(ll a,ll b){
	return b==0?a:gcd(b,a%b);
}
ll exgcd(ll a,ll b,ll &x,ll &y){
    if (b==0){
        x=1,y=0;
        return a;
    }
    ll q=exgcd(b,a%b,y,x);
    y-=a/b*x;
    return q;
}
ll ans(ll M[], ll R[], ll n)
{
    ll m = M[1], r = R[1];
    ll x, y, flag = 1;
    for(ll i = 2; i <= n; i++)
    {
        ll d = gcd(m, M[i]), c = R[i] - r;
        if(c % d != 0)
        {
            flag = 0;
            break;
        }
        exgcd(m/d, M[i]/d, x, y);
        ll tm = M[i] / d;
        x = ((c/d * x) % tm + tm) % tm;
        r = r + x*m;
        m = m/d * M[i];
        r %= m;
    }
    if(flag==0)r=-1;
    return r;
}
int main(){
	fab[1]=1;
	fab[2]=1;
	vis[1]=1;
	for(int i=3;;i++){
		fab[i]=fab[i-1]+fab[i-2];
		vis[fab[i]]=1;
		if(fab[i]>1e15)break;
	}
	int k;
	scanf("%d",&k);
	for(int i=1;i<=k;i++){
		scanf("%lld %lld",&a[i],&b[i]);
	}
	ll n=ans(a,b,k);
	if(n==-1){
		printf("Tankernb!\n");
	}
	else if(vis[n]!=1){
		printf("Zgxnb!\n");
	}
	else{
		printf("Lbnb!\n");
	}
}