Who is better?

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值