算法部分参考:
https://blog.csdn.net/u010468553/article/details/38346195
# -*- coding: UTF-8 -*-
from functools import reduce
def Get_Mi(m_list,M):
M_list=[]
for mi in m_list:
M_list.append(M//mi)
return M_list
def Get_ei_list(M_list,m_list):
ei_list=[]
for i in range(len(M_list)):
ei_list.append(Get_ei(M_list[i],m_list[i]))#这里就原来有改动,来是数组
return ei_list
def Get_ei(a,b):
# 计算ei
# 请在此处添加代码 #
# *************begin************#
i=1
while True:
if (a*i)%b ==1:
return i
i+=1
# **************end*************#
def crt(a_list,m_list):
# 计算中国剩余定理,返回计算结果
# 请在此处添加代码 #
# *************begin************#
M = reduce(lambda x, y: x*y,m_list)
Mi = Get_Mi(m_list,M)
ei = Get_ei_list(Mi,m_list)
'''
result = map(lambda x,y,z:x*y*z,Mi,ei,a_list)
没试过不知道行不行
'''
sums=0
for x,y,z in zip(ei,Mi,a_list):
sums += (x*y*z) #233
#求解
return sums%M
# **************end*************#
if __name__=='__main__':
a_list= list(map(int,input().split(",")))
m_list= list(map(int,input().split(",")))
print(crt(a_list,m_list))