自己看的思路↑(不喜勿喷)。
每次计算的结果保存在a1,m1中,以x%2=1,x%3=2为例,来探索出转换公式,for循环n-1次即可。
def exgcd(a,b):
if(not b):
return 1,0,ay,x,d=exgcd(b,a%b)
x,y=x,y-a//b*x
return x,y,dn=int(input())
m1,a1=map(int,input().split())
for i in range(n-1):
m2,a2=map(int,input().split())
x,y,d=exgcd(m1,m2)
'''
if (a2 - a1) % d:
flag = 1
break
'''
a=x*(a2-a1)//d
a1=(a*m1+a1)
m1=m1*m2//da1%=m1
print(a1,m1,x,y)print(a1%m1)
#'''
48
2 1
3 2
4 1
5 4
6 5
7 4
8 1
9 2
10 9
11 0
12 5
13 10
14 11
15 14
16 9
17 0
18 11
19 18
20 9
21 11
22 11
23 15
24 17
25 9
26 23
27 20
28 25
29 16
30 29
31 27
32 25
33 11
34 17
35 4
36 29
37 22
38 37
39 23
40 9
41 1
42 11
43 11
44 33
45 29
46 15
47 5
48 41
49 46
2022040920220409
'''