[关闭]
@Lin-- 2018-12-23T14:12:37.000000Z 字数 2492 阅读 255

CRT's Homeworks

计算机数学


  1. Using CRT to solve:
    x ≡ 8 (mod 11)
    x ≡ 3 (mod 19)

    解:令

    由拓展欧几里得算法解得


    解得

  2. Using CRT to solve the system of congruence:
    x ≡ 1 (mod 5)
    x ≡ 2 (mod 7)
    x ≡ 3 (mod 9)
    x ≡ 4 (mod 11)

    解:由题得:
    令:
    所以





    因为


    由拓展欧几里得算法解得


    解得

  3. Write a program(C or Python) to solve CRT

  1. #algorithm of egcd
  2. def egcd(a,b):
  3. r0,r1,s0,s1=1,0,0,1
  4. while b:
  5. q,a,b=a//b,b,a%b
  6. r0,r1=r1,r0-q*r1
  7. s0,s1=s1,s0-q*s1
  8. return r0
  9. #algorithm of CRT
  10. def CRT(a,m):
  11. M,x=1,0
  12. b=list()
  13. b_=list()
  14. for n in range(len(m)):
  15. M=M*m[n];
  16. for i in range(len(m)):
  17. b.append(M//m[i])
  18. '''
  19. compute b_
  20. because b_[i]*b[i]=1(mod m[i])
  21. so b[i]*b_[i]-1=c1*m[i]
  22. than b[i]*b_[i]+c2*m[i]=1
  23. use egcd to compute the result
  24. '''
  25. b_.append(egcd(b[i],m[i]))
  26. '''
  27. when the result is a negative number
  28. let it become a positive number which is a Equivalence class about b_[i]
  29. '''
  30. if b_[i]<0:
  31. b_[i]=b_[i]%m[i]
  32. x=(a[i]*b[i]*b_[i]+x)%M
  33. return x
  34. #test the algorithm
  35. l0=[1,2,3,4]
  36. l1=[5,7,9,11]
  37. print(CRT(l0,l1))
  1. Complete the proof that it is an isomorphism from
    解:
    ①定义f是从


    设所有


    因为



    满足单射条件
    任取
    由于
    故存在




    总能找到
    故满足满射条件
    是一个双射函数

    ③设






    1. Let p = 5 and q = 7, n = pq. Please explicitly give the
      correspondece between Hint: programming is permitted.
  1. #judge prime number
  2. def gcd(a,b):
  3. if b==0:
  4. return a
  5. else:
  6. return gcd(b,a%b)
  7. #generate an array contain numbers from 1 to a-1 which is coprime to a
  8. def array_prime(a):
  9. l=[]
  10. for i in range(a):
  11. if gcd(i,a)==1:
  12. l.append(i)
  13. return l
  14. def f(p,q):
  15. n,i=p*q,0
  16. l2=[]
  17. array_prime(n)
  18. for j in array_prime(n):
  19. l1=[j,(j%p,j%q)]
  20. l2.append(l1)
  21. return l2
  22. print(f(5,7))

result
[[1, (1, 1)], [2, (2, 2)], [3, (3, 3)], [4, (4, 4)], [6, (1, 6)], [8, (3, 1)], [9, (4, 2)], [11, (1, 4)], [12, (2, 5)], [13, (3, 6)], [16, (1, 2)], [17, (2, 3)], [18, (3, 4)], [19, (4, 5)], [22, (2, 1)], [23, (3, 2)], [24, (4, 3)], [26, (1, 5)], [27, (2, 6)], [29, (4, 1)], [31, (1, 3)], [32, (2, 4)], [33, (3, 5)], [34, (4, 6)]]

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注