import gmpy2

# m = 6599256672879500262705451905844
n = 75859701273785084796521795848145484579515606171618136219758020810283096757609740192656998501991908513576682475255970752306923138479868561572777782326668872780440813804378898465215079538005935985500741504629349843580827325984800142220126556206579493235820796947230135706944648351499461629510523738134494600296377835624162629836946605006870311925907109173898194126177718131665623133437618472885041791348579782095512695087612119908997197399456037395423472864001988011919083369927935852981377607245109313826915000565229208794383982811618083506702112075473832755367566165666608791382693797849788363488845124306789577310752272780831801189617657465552264378463941425162929
e = 65537
c = 51224317448992753108285059349748475277060216772693312646320327186279824291972909577029168511287999052029745075666539094711622070580089718266573171878677969536614194458240640914737965150147614970781654023773607001512380219144038957063688025431539789656095364072356004946817600339860389935769732336736971276277252452358957923497138429989390083364852922780016145240933222695999295054718289504491528963366104960079294673342598406122543066683262300803502638319418199135719266752901676982075065367210554290111877236880049255823612164793077358326256251607298141012222209595968733376477679369991611777435682633382549225368309349707367020833364287537636096896124168705571599    # q = int(gmpy2.digits(p, 2))

def discrete_log(g, h, p):
    """
    Calculates the discrete logarithm of h to the base g modulo p.

    Args:
        g: The base (generator).
        h: The element whose logarithm is to be found.
        p: The modulus (prime).

    Returns:
        The discrete logarithm x, or None if no solution exists.
    """
    for x in range(1, p):
        if gmpy2.powmod(g, x, p) == h:
            return x
    return None

# Example usage

x = discrete_log(e, c, n)

if x is not None:
    print(f"The discrete logarithm of {h} to the base {g} modulo {p} is {x}")
else:
    print("No solution found.")


p = gmpy2.isqrt(n)
q = p
