cinta作业9

本文介绍了如何运用中国剩余定理(CRT)来求解同余方程组,如x≡8(mod 11)和x≡3(mod 19),并给出详细的计算过程。此外,还探讨了当m和n互素时,如果x≡a(mod m)和x≡a(mod n),则x模mn也等于a的理论依据。最后,提出了编程题作为练习。
  • 利用crtcrtcrt求解x≡8(mod 11),x≡3(mod 19)x\equiv 8(mod \space11),x\equiv3(mod\space 19)x8(mod 11),x3(mod 19)

    n=11∗19=209n=11*19=209n=1119=209
    19 mod 1119 \space mod\space 1119 mod 11下的乘法逆元为77711 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=1978+1173=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)x1(mod 5),x2(mod 7),x3(mod 9),x4(mod 11)
    M=5∗7∗9∗11=3465M = 5*7*9*11=3465M=57911=3465b1=M/5=693b_1=M/5 = 693b1=M/5=693693 mod 5693\space mod \space 5693 mod 5下的乘法逆元为222b2=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=495b21=3,b3=M/9=385,b3−1=4b_3^{-1}=4b31=4b4=M/11=315,b4−1=8b_4 = M/11=315,b_4^{-1}=8b4=M/11=315,b41=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=69321+49532+38543+31584=19056(mod M)=1731

  • m和nm和nmn为互素的正整数,a>0a>0a>0为一个正整数,如果
    x≡a(mod m) x\equiv a(mod\space m) xa(mod m)

    x≡a(mod n) x\equiv a(mod\space n) xa(mod n)

    xxxmnmnmn等于什么?为什么?
    等于aaa,从第一个同余式得到x=mt+a,t∈Zx=mt+a,t\in \Zx=mt+a,tZ,把xxx代入第二个同余式得到mt+a≡a(mod n)mt+a\equiv a(mod \space n)mt+aa(mod n),整理得mt≡0(mod n)mt\equiv 0(mod \space n)mt0(mod n),所以mt mod n=0mt\space mod\space n=0mt mod n=0,因为m,nm,nm,n互素,所以∃k∈Z\exist k\in \ZkZ,使得t=knt=knt=kn,所以x=knm+ax=knm+ax=knm+a,即x≡a(mod mn)x\equiv a(mod \space mn)xa(mod mn),所以xxxmnmnmn等于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)
    
    
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值