Who is better?
徐州网络赛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!"); } }
随机推荐
- noip2015day2-运输计划
题目描述 公元$ 2044 $年,人类进入了宇宙纪元. \(L\) 国有 \(n\) 个星球,还有 \(n-1\) 条双向航道,每条航道建立在两个星球之间,这 \(n-1\) 条航道连通了 \(L\) ...
- PythonDay15
第十五章装饰器_递归 今日内容 带参数装饰器 多个装饰器修饰一个函数 递归 带参数的装饰器 # 判断argv,当登录不同的网页,会有不同的装饰效果def auth(argv): def warpp ...
- Homebrew学习(六)之替换及重置homebrew、Homebred Core、Homebrew cask默认源
替换及重置homebrew默认源 中科大源 替换官方源: // 替换brew.git: cd "$(brew --repo)" git remote set-url origin ...
- js将时间戳转化为年月日时分秒
export const dateFormatter = (nows) => { if (!nows) return '' var now = new Date(nows) var year = ...
- js 元素offset,client , scroll 三大系列总结
1,element.offsetWidth : 包括 padding 和 边框 2,element.clientWidth : 包括 padding ,不包含边框 , 内容超出会溢出盒子的时候,就用s ...
- 动态class,style,src绑定写法 vue
:class="{active:menuName===item.title}" :style="thisTitle==='一张图展示'?styles:''" : ...
- laravel查询数据库获取结果如何判断是否为空?
laravel 查询数据库获取结果如何判断是否为空? 大家使用的场景是这样的: 1 $users = DB::table('users')->where('id',$id)->get(); ...
- C/C++ 零碎知识点
传递参数的一般指导原则: 对于使用传递的值而不做修改的函数: 如果数据对象很小,比如内置类型或者小型结构,按值传递. 如果数据对象是数组,只能使用指针,并将指针生命为指向const的指针. 如果数据对 ...
- Python excel读写
# coding=utf-8 print "----------------分割线 xlrd--------------------" import xlrd #打开一个wordb ...
- 如何将vim打造成Linux下的source insight
编写者:龙诗科 邮箱:longshike2010@163.com 2016-01-06 众所周知,windows下的source insight是阅读项目代码的神器,其神奇之处在于可以根据当前鼠标所指 ...