徐州网络赛A

所谓斐波那契博弈

考场推了个假规律自闭==

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Scanner; public class Main { static BigInteger m[]=new BigInteger[15];
static BigInteger c[]=new BigInteger[15];
static int n;
static BigInteger _m;
static BigInteger x,y;
static long A[]=new long[400000];
static int cnt=0;
static void init()
{
A[0]=1;
A[1]=1;
for(cnt=2;;cnt++){
A[cnt]=A[cnt-1]+A[cnt-2];
if(A[cnt]>1e15){
break;
}
}
}
public static BigInteger[] ex_gcd(BigInteger a,BigInteger b){
BigInteger ans;
BigInteger[] result=new BigInteger[3];
if(b.equals(BigInteger.ZERO))
{
result[0]=a;
result[1]=BigInteger.ONE;
result[2]=BigInteger.ZERO;
return result;
}
BigInteger [] temp=ex_gcd(b,a.mod(b));
ans = temp[0];
result[0]=ans;
result[1]=temp[2];
result[2]=temp[1].subtract((a.divide(b)).multiply(temp[2]));
//System.out.println(result[0]+" "+result[1]+" "+result[2]);
return result;
}
static BigInteger getInv(BigInteger a,BigInteger md)
{
//x=BigInteger.ZERO;y=BigInteger.ZERO;
BigInteger d[]=ex_gcd(a,md);
//System.out.println(a+" "+md);
//System.out.println(x+" "+y);
//System.out.println(d[1]);
return (d[0].equals(BigInteger.ONE))?(d[1].add(md)).mod(md):BigInteger.valueOf(-1);
}
static BigInteger exCRT(int n)
{
BigInteger m1,m2,c1,c2,d;
for(int i=2;i<=n;i++)
{
m1=m[i-1];m2=m[i];c1=c[i-1];c2=c[i];
d=m1.gcd(m2);
if(!(c2.subtract(c1)).mod(d).equals(BigInteger.ZERO))return BigInteger.valueOf(-1);//此时无法合并
m[i] = m[i-1] .multiply(m[i]).divide(d) ;
BigInteger t=(c2.subtract(c1)).divide(d);
//System.out.println(t);
c[i] = t.multiply( getInv(m1.divide(d),m2.divide(d))) .mod ( m2.divide(d) ).multiply(m1) .add(c1) ;
//System.out.println(c[i]);
// System.out.println(getInv(m1.divide(d),m2.divide(d)));
c[i] = ( (c[i] .mod(m[i])) .add(m[i]) ) .mod( m[i]);
// System.out.println(m[i]);
}
return c[n];
}
public static void main(String[] args) {
init();
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
// int k=0;
for(int i=1;i<=n;i++){
m[i]=sc.nextBigInteger();
c[i]=sc.nextBigInteger(); } BigInteger ans=exCRT(n); long N=ans.longValue();
if(N==-1){
System.out.println("Tankernb!");
return ;
}
/* if(N==0){
BigInteger t=m[1],a=BigInteger.ONE;
for(int i=1;i<=n;i++){
t=m[i].gcd(t);
a=a.multiply(m[i]);
}
a=a.divide(t);
N=a.longValue();
}*/
if(N<=3){
System.out.println("Lbnb!");
return;
}
if(N==4){
System.out.println("Zgxnb!");
return ;
}
if(N==5){
System.out.println("Lbnb!");
return;
}
for(int i=0;i<=cnt;i++){
if(A[i]==N){
System.out.println("Lbnb!");
return;
}
}
System.out.println("Zgxnb!"); } }

随机推荐

  1. 工作中常用到的JS验证

    Common.js // JavaScript Document // _ooOoo_ // o8888888o // 88" . "88 // (| -_- |) // O\ = ...

  2. vim学习(三)之命令

    参考 Linux vi/vim vim常用命令总结

  3. MySQL索引优化 笔记

    少取字段,建立合理的索引 表优化: 1 定长与变长分离 如果都是定长 查询比较快 因为每一行的字节都是固定的 fixed 2 常用字段和不常用字段要分离 用户表 常用 放主表 个人介绍不常用 还比较长 ...

  4. javaScript运动框架之匀速运动

    运动框架 1.在开始运动时,关闭已有定时器 2.把运动和停止隔开(if/else) 匀速运动的停止条件 运动终止条件:距离足够近 Demo代码 <!DOCTYPE html> <ht ...

  5. Android多渠道打包且根据不同产品打包不同的assets资源目录

    因为项目中存在多种环境,既要区分bebug与release版本,release又要区分测试环境与生产上线环境,每次打包都得浪费不少的等待时间:并且哪个版本有问题还得去切换环境一个个打包,关键是还得牢记 ...

  6. python变量、对象和引用你真的明白了吗

    python变量.对象和引用你真的明白了吗 变量.对象和引用 Python不像C++,Java等语言一样,他们可以不用事先声明变量类型而直接对变量进行赋值.对Python语言来讲,对象的类型和内存都是 ...

  7. LVS实现负载均衡原理及安装配置 负载均衡

    LVS实现负载均衡原理及安装配置 负载均衡集群是 load balance 集群的简写,翻译成中文就是负载均衡集群.常用的负载均衡开源软件有nginx.lvs.haproxy,商业的硬件负载均衡设备F ...

  8. module.exports exports npm --save

    CommonJS模块规范和ES6模块规范完全是两种不同的概念 Node应用由模块组成,采用CommonJS模块规范 var x = 5; var addX = function (value) { r ...

  9. 现身说法:面对DDoS攻击时该如何防御?

    上周,我们的网站遭到了一次DDoS攻击.虽然我对DDoS的防御还是比较了解,但是真正遇到时依然打了我个措手不及.DDoS防御是一件比较繁琐的事,面对各种不同类型的攻击,防御方式也不尽相同.对于攻击来的 ...

  10. cobbler装机系统部署

    1.cobbler安装 [root@linux-node1 ~]# cp /etc/cobbler/settings{,.ori} # 备份 # server,Cobbler服务器的IP. sed - ...