Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. def jacobi(a, n):
  2. assert(n > a > 0 and n%2 == 1)
  3. t = 1
  4. while a != 0:
  5. while a % 2 == 0:
  6. a /= 2
  7. r = n % 8
  8. if r == 3 or r == 5:
  9. t = -t
  10. a, n = n, a
  11. if a % 4 == n % 4 == 3:
  12. t = -t
  13. a %= n
  14. if n == 1:
  15. return t
  16. else:
  17. return 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement