-
利用crtcrtcrt求解x≡8(mod 11),x≡3(mod 19)x\equiv 8(mod \space11),x\equiv3(mod\space 19)x≡8(mod 11),x≡3(mod 19)
令n=11∗19=209n=11*19=209n=11∗19=209
19 mod 1119 \space mod\space 1119 mod 11下的乘法逆元为777,11 mod 1911\space mod \space 1911 mod 19下的乘法逆元为777,所以x=19∗7∗8+11∗7∗3=1295(mod n)=41x=19*7*8+11*7*3=1295(mod \space n)=41x=19∗7∗8+11∗7∗3=1295(mod n)=41, -
利用crtcrtcrt求解x≡1(mod 5),x≡2(mod 7),x≡3(mod 9),x≡4(mod 11)x\equiv 1(mod \space5),x\equiv2(mod\space 7),x\equiv3(mod\space 9),x\equiv4(mod\space 11)x≡1(mod 5),x≡2(mod 7),x≡3(mod 9),x≡4(mod 11)
M=5∗7∗9∗11=3465M = 5*7*9*11=3465M=5∗7∗9∗11=3465,b1=M/5=693b_1=M/5 = 693b1=M/5=693,693 mod 5693\space mod \space 5693 mod 5下的乘法逆元为222,b2=M/7=495,b2−1=3,b3=M/9=385b_2=M/7=495,b_2^{-1} = 3,b_3 = M/9=385b2=M/7=495,b2−1=3,b3=M/9=385,b3−1=4b_3^{-1}=4b3−1=4 ,b4=M/11=315,b4−1=8b_4 = M/11=315,b_4^{-1}=8b4=M/11=315,b4−1=8,所以x=693∗2∗1+495∗3∗2+385∗4∗3+315∗8∗4=19056(mod M)=1731x=693*2*1+495*3*2+385*4*3+315*8*4=19056(mod \space M)=1731x=693∗2∗1+495∗3∗2+385∗4∗3+315∗8∗4=19056(mod M)=1731 -
设m和nm和nm和n为互素的正整数,a>0a>0a>0为一个正整数,如果
x≡a(mod m) x\equiv a(mod\space m) x≡a(mod m)x≡a(mod n) x\equiv a(mod\space n) x≡a(mod n)
xxx模mnmnmn等于什么?为什么?
等于aaa,从第一个同余式得到x=mt+a,t∈Zx=mt+a,t\in \Zx=mt+a,t∈Z,把xxx代入第二个同余式得到mt+a≡a(mod n)mt+a\equiv a(mod \space n)mt+a≡a(mod n),整理得mt≡0(mod n)mt\equiv 0(mod \space n)mt≡0(mod n),所以mt mod n=0mt\space mod\space n=0mt mod n=0,因为m,nm,nm,n互素,所以∃k∈Z\exist k\in \Z∃k∈Z,使得t=knt=knt=kn,所以x=knm+ax=knm+ax=knm+a,即x≡a(mod mn)x\equiv a(mod \space mn)x≡a(mod mn),所以xxx模mnmnmn等于aaa。 -
编程题
#只接受两个同余方程的程序 def egcd(a, b, f1, s1): while b != 0: f1, s1 = s1, f1 - a // b * s1 a, b = b, a%b return f1, a def get_multiply_reverse(a, b): r1, gcf = egcd(a, b, 1, 0) if gcf != 1: return -1 else: return r1 % b def crt(mod_m_num, m, mod_n_num, n): reverse_n = get_multiply_reverse(n, m) reverse_m = get_multiply_reverse(m, n) ans = (mod_m_num * n * reverse_n + mod_n_num * m * reverse_m) % (m * n) return ans n1, n2, n3, n4 = map(int, input().split(' ')) x = crt(n1, n2, n3, n4) print(x)#接受多个同余方程 def egcd(a, b, f1, s1): while b != 0: f1, s1 = s1, f1 - a // b * s1 a, b = b, a%b return f1, a def get_multiply_reverse(a, b): r1, gcf = egcd(a, b, 1, 0) if gcf != 1: return -1 else: return r1 % b def multiply_crt(*args): mod_num = [] mod = [] for i in range(len(args)): if i % 2 == 0: mod_num.append(args[i]) else: mod.append(args[i]) s = 1 for item in mod: s *= item ans = 0 for i in range(len(mod)): n = s / mod[i] mod_reverse = get_multiply_reverse(n, mod[i]) ans += mod_num[i] * n * mod_reverse return ans % s n1, n2, n3, n4, n5, n6, n7, n8 = map(int, input().split(' ')) x = multiply_crt(n1, n2, n3, n4, n5, n6, n7, n8) print(x)
cinta作业9
最新推荐文章于 2023-12-03 22:53:39 发布
本文介绍了如何运用中国剩余定理(CRT)来求解同余方程组,如x≡8(mod 11)和x≡3(mod 19),并给出详细的计算过程。此外,还探讨了当m和n互素时,如果x≡a(mod m)和x≡a(mod n),则x模mn也等于a的理论依据。最后,提出了编程题作为练习。
441

被折叠的 条评论
为什么被折叠?



