题意:就是中国剩余定理
题解:写上板子之后过不去,很奇怪,然后发现卡大数。。。。
python走一波!
x=0;y=0
def mul(a,b,m)-> int:
return int(a*b%m)
def exgcd(a,b)-> int:
global x, y
if(b==0):
x=1
y=0
return a
gcd=exgcd(b,a%b)
tp=x
x=y
y=tp-a//b*y
return gcd
def excrt(ai,bi,n)-> int:
global x,y
M=bi[1]
ans=ai[1]
for i in range(2,n+1):
a=M
b=bi[i]
c=(ai[i]-ans%b+b)%b
gcd=exgcd(a,b)
bg=b//gcd
#print(c%gcd)
if(c%gcd!=0):
return -1
x=mul(x,c//gcd,bg)
ans+=x*M
M*=bg
ans=(ans%M+M)%M
return (ans%M+M)%M
n,m=map(int,input().split())
ai=[0]
bi=[0]
for i in range(1,n+1):
aa,bb=map(int,input().split())
ai.append(aa)
bi.append(bb)
ans = excrt(bi,ai,n)
if ans==-1:
print("he was definitely lying")
elif ans>m:
print("he was probably lying")
else:
print(int(ans))