Kryptografia/miniprojekt2/4-faktoryzacja.py

30 lines
415 B
Python
Raw Normal View History

2021-11-24 23:47:52 +01:00
import random, math
n = random.getrandbits(50)
print(n)
k = 2
pom = math.sqrt(n)
factors = [1]
i = 1
d = -1
while n > 1 and k <= pom:
while n % k == 0:
n = n // k
factors.append(k)
if k < 3:
k += 1
else:
k = 6 * i + d
if d == 1:
d = -1
i += 1
else:
d = 1
if len(factors) == 0:
factors.append(n)
print(factors)