题意:
类似于有N个石子,先手第一次不能拿完,每次后手只能拿 1 到 前一次拿的数量*2之间的数量,不能拿时则输
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static BigInteger x = BigInteger.ZERO, y = BigInteger.ZERO;
public static BigInteger[] ai = new BigInteger[110];
public static BigInteger[] bi = new BigInteger[110];
public static BigInteger[] fi = new BigInteger[110];
public static int n;
@SuppressWarnings("resource")
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
fi[1]=BigInteger.valueOf(2);
fi[2]=BigInteger.valueOf(3);
for(int i=3; i <= 100; i++) {
fi[i] = fi[i-1].add(fi[i-2]);
}
n = cin.nextInt();
for (int i = 1; i <= n; i++) {
bi[i] = cin.nextBigInteger();
ai[i] = cin.nextBigInteger();
}
BigInteger ans = excrt();
if(ans.compareTo(BigInteger.valueOf(-1)) == 0)
System.out.println("Tankernb!");
else {
int f=0;
for(int i=2;i<=100;i++)
if(ans.compareTo(fi[i])==0)
f=1;
if(f==1)
System.out.println("Lbnb!");
else
System.out.println("Zgxnb!");
}
}
private static BigInteger excrt() {
BigInteger M = bi[1], ans = ai[1];
for (int i = 2; i <= n; i++) {
BigInteger a = M, b = bi[i], c = ai[i].subtract(ans.mod(b)).add(b).mod(b);
BigInteger gcd = exgcd(a, b), bg = b.divide(gcd);
if (c.mod(gcd).compareTo(BigInteger.ZERO) != 0)
return BigInteger.valueOf(-1);
x = x.multiply(c.divide(gcd));
ans = ans.add(x.multiply(M));
M = M.multiply(bg);
ans = ans.mod(M).add(M).mod(M);
}
ans = ans.mod(M).add(M).mod(M);
return ans;
}
private static BigInteger exgcd(BigInteger a, BigInteger b) {
if (b.compareTo(BigInteger.ZERO) == 0) {
x = BigInteger.ONE;
y = BigInteger.ZERO;
return a;
}
BigInteger gcd = exgcd(b, a.mod(b));
BigInteger k = x;
x = y;
y = k.subtract(a.divide(b).multiply(y));
return gcd;
}
}