Fast Factorisation (Python Implementation)
sqrt is expensive.  You can avoid it by reworking your test condition from:

p &gt; int(sqrt(n)) + 1


to:

p*p &gt; n




You can skip one while n%p == 0 iteration by initializing e = 1 and unconditionally dividing by p once you’ve found a prime factor:

if n%p == 0:
    e = 1
    n //= p
    while n%p == 0:
        # ...etc...




Avoid putting “then” statements on the same line as  the if statement:  place the “then” statement indented on the next line.



The algorithm should be a comment, not part of the """docstring"""; callers generally only care about how to use the function, not the implementation details.