from collections import Counter
from math import gcd, prod, isqrt
import random
def brent(n):
y, c, m = random.randint(1, n - 1), random.randint(1, n - 1), random.randint(1, n - 1)
g, r, q = 1, 1, 1
while g == 1:
x = y
for i in range(r): y = (y * y + c) % n
k = 0
while k < r and g == 1:
ys = y
for i in range(min(m, r - k)): y, q = (y * y + c) % n, (q * abs(x - y)) % n
g, k = gcd(q, n), k + m
r *= 2
if g == n:
while True:
ys, g = (ys * ys + c) % n, gcd(abs(x - ys), n)
if g > 1: break
return g
def factors(n):
c = Counter()
while n % 2 == 0: c[2], n = c[2] + 1, n // 2
for p in range(3, 100001, 2):
while n % p == 0: c[p], n = c[p] + 1, n // p
while n > 1:
p = brent(n)
while n % p == 0: c[p], n = c[p] + 1, n // p
if n > 1: c[n] += 1
return c
print(factors(16546864687987117))
To embed this program on your website, copy the following code and paste it into your website's HTML: