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!"); } }
随机推荐
- [codeforces1234F]Yet Another Substring Reverse
题目链接 大致题意为将某个子串进行翻转后,使得不包含相同字符的字符子串长度最长.只能翻转一次或零次. 设一个子串的状态为包含字符的二进制.如子串为$abacd$,则状态为$00000000000000 ...
- PhpStorm配置Xdebug调试
安装xdebug 去官网下载对应版本的xdebug扩展 XDEBUG EXTENSION FOR PHP | DOWNLOADS 如何选择正确版本 输出phpinfo()函数的内容 查看输出页面的网页 ...
- python3的base64编解码
使用python3的base64编解码实现字符串的简易加密解密 引言: 在一些项目中,接口的报文是通过base64加密传输的,所以在进行接口自动化时,需要对所传的参数进行base64编码,对拿到的响应 ...
- APT高持续渗透攻击-后门篇
APT是指高级持续性威胁, 利用先进的攻击手段对特定目标进行长期持续性网络攻击的攻击形式,APT攻击的原理相对于其他攻击形式更为高级和先进,其高级性主要体现在APT在发动攻击之前需要对攻击对象的业务流 ...
- NTFS,FAT32和exFAT文件系统的区别
NTFS,FAT32和exFAT文件系统的区别 本文所有资料来源于网络,仅做个人学习使用,如有侵权,请联系删除 1.什么是文件系统 文件系统是系统对文件的存放排列方式,不同格式的文件系统关系到数据是如 ...
- 【转载】Django自带的注册登陆功能
1.登陆 知识点: a.auth.authenticate(username=name值, password=password值) 验证用户名和密码 b.auth.login(request, use ...
- 初探 -1 JavaScript
JavaScript 教程 JavaScript 是 Web 的编程语言. 所有现代的 HTML 页面都使用 JavaScript. JavaScript 非常容易学. 本教程将教你学习从初级到高级J ...
- 81. Search in Rotated Sorted Array II (JAVA)
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e. ...
- iOS崩溃分析
崩溃的分析 最近修复了一些iOS项目的崩溃,想分析总结一下这些崩溃的原因,以及预防.崩溃的原因一般有下面几种: 内存访问错误(这个出现的比较多,原因多种多样) 非法指令的执行(超出权限范围内的指令) ...
- juniper 命令
show chassis hardware 查看系统硬件配置,fpc表示板卡,pic表示板卡中的槽位,xcvr表示板卡中的槽位的端口位置 show chassis envirmonent 查看系统运行 ...