//Find prime factorization of a number
in O(log(n)) Time complexity
from math import ceil,sqrt
MAX=100001
spf=[0 for i in range(MAX)]
def sieve():
spf[1]=1
for i in range(2,MAX):
spf[i]=i
for i in range(4,MAX,2):
spf[i]=2
for i in range(3,ceil(sqrt(MAX))):
if(spf[i]==i):
for j in range(i*i,MAX,i):
if(spf[j]==j):
spf[j]=i
def primefactor(n):
res=[]
while (n!=1):
res.append(spf[n])
n=n//spf[n]
return res
sieve()
p=primefactor(12246)
for i in range(len(p)):
print(p[i],end=" ")
0 Comments