Skip to content

Instantly share code, notes, and snippets.

@b1ek
Created September 17, 2022 13:13
Show Gist options
  • Save b1ek/ff3049b8ed8db74c9972536517d033c3 to your computer and use it in GitHub Desktop.
Save b1ek/ff3049b8ed8db74c9972536517d033c3 to your computer and use it in GitHub Desktop.
Carmichael function python
from math import gcd
def carmi(n):
    copr = [x for x in range(1, n) if gcd(x, n) == 1]
    k = 1
    while not all(pow(x, k, n) == 1 for x in copr):
        k += 1
    return k

If you get an import error on line 1, change math to fractions and see how it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment