徐州网络赛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. [转帖]Linux下inotify监控文件夹状态,发生变化后触发rsync同步

    Linux下inotify监控文件夹状态,发生变化后触发rsync同步 https://www.cnblogs.com/fjping0606/p/6114123.html 1.安装工具--inotif ...

  2. Luogu P1450 [HAOI2008]硬币购物

    题目 一个很自然的想法是容斥. 假如只有一种硬币,那么答案就是没有限制的情况下买\(s\)的方案数减去强制用了\(d+1\)枚情况下买\(s\)的方案数即没有限制的情况下买\(s-c(d+1)\)的方 ...

  3. js 获取ip和城市

    <script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>

  4. java tomcat服务器

    1.什么是javaweb? Java web,是用java技术来解决相关web互联网领域的技术的总称. web包括:web服务器和web客户端两部分.java在最早web客户端的应用有java app ...

  5. 从入门到自闭之Python三大器--迭代器

    函数名的第一类对象(概述): 使用方式: 函数名可以当做值赋值给变量 def func(): print(1) print (func) #查看函数的内存地址 a = func print (a) # ...

  6. tf-图像预处理

    tensorflow 中自带了很多图像处理的方法,基本都在 tf.image 模块中,虽然不如 opencv 强大,但也比较常用,这里做个记录. 图像编解码 1. 用 tf 的方法读取图片后,都需要进 ...

  7. 实用且堪称神器的Chrome插件推荐(转)

    出处: http://tengj.top/2018/02/17/ggcj/ 前言 相信很多人都在使用 Chrome 浏览器,其流畅的浏览体验得到了不少用户的偏爱,但流畅只是一方面, Chrome 最大 ...

  8. MYSQL 的事物处理(四大特性)

    什么是事物? MySQL 事务主要用于处理操作量大,复杂度高的数据.比如说,在人员管理系统中,你删除一个人员,你即需要删除人员的基本资料,也要删除和该人员相关的信息,如信箱,文章等等,这样,这些数据库 ...

  9. 运维LVS三种模式十种调度算法

    一.LVS简介 LVS(Linux Virtual Server)即Linux虚拟服务器,是由章文嵩博士主导的开源负载均衡项目,目前LVS已经被集成到Linux内核模块中.该项目在Linux内核中实现 ...

  10. css3之新增伪类

    css3新增了许多伪类,但是IE8以及更低版本的IE浏览器不支持css3伪类,所以在使用时要是涉及到布局等意象全局的样式,应该多考虑一下. 1.elem:nth-child(n) 这个伪类选中父元素下 ...