You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
485 B

  1. load("number-theory.sage")
  2. #####
  3. # Chinese Remainder Theorem tests
  4. a_i = [5, 3, 10]
  5. m_i = [7, 11, 13]
  6. M = 1001
  7. assert crt(a_i, m_i, M) == 894
  8. a_i = [3, 8]
  9. m_i = [13, 17]
  10. M = 221
  11. assert crt(a_i, m_i, M) == 42
  12. #####
  13. # gcd, using Binary Euclidean algorithm tests
  14. assert gcd(21, 12) == 3
  15. assert gcd(1_426_668_559_730, 810_653_094_756) == 1_417_082
  16. #####
  17. # Extended Euclidean algorithm tests
  18. assert egcd(7, 19) == (1, -8, 3)
  19. #####
  20. # Inverse modulo N tests
  21. assert inv_mod(7, 19) == 11