while 1:
try:
p=[int(x) for x in stdin.readline().split()]
except:
break
k=[int(x) for x in stdin.readline().split()]
s=int(1);ans=0;mx=-1
for i in len(p):
s=s*p[i]
if mx<p[i]:
mx=p[i]
for i in len(p):
m=s/p[i]
c=m*pow(m%p[i],p[i]-2,p[i])
ans+=k[i]*c;ans%=s
while ans<=mx:
ans+=s
print(ans)
這題測資點#5 由 1.0s 改為 1.3s 後重測。(2019年 server 更新後,系統變慢了,)
測資點#5 (17%): 1.3s