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");
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值