<filename>A/A_k_Factorization.py
import sys,math,io,os,time,itertools,collections
mod=10**9+7
sys.setrecursionlimit(10000)
i=sys.stdin.readline
p=sys.stdout.write
#use sys.stdout.write() (remember to convert to str b4 and concatenate "\n")
global start,end

def primefac(n):
    l=[]
    while n%2==0:
        l.append(2)
        n=n//2
    p=3
    while p*p<=n:
        while n%p==0:
            l.append(p)
            n=n//p
        p+=2
    if n>2:
        l.append(n)
    return l

def main():
    n,m=[int(k) for k in i().split()]
    l=primefac(n)
    if len(l)<m:
        p("-1\n")
    else:
        fin=[]
        prod=l[0]
        for k in range(1,len(l)-m+1):
            prod*=l[k]
        fin.append(str(prod))
        for k in range(len(l)-m+1,len(l)):
            fin.append(str(l[k]))
        p(" ".join(fin)+"\n")

t=1
#t=int(i())
start=time.perf_counter()
for _ in range(t):
    main()
end=time.perf_counter()
#print(end-start)
<filename>A/A_k_Factorization.py
import sys,math,io,os,time,itertools,collections
mod=10**9+7
sys.setrecursionlimit(10000)
i=sys.stdin.readline
p=sys.stdout.write
#use sys.stdout.write() (remember to convert to str b4 and concatenate "\n")
global start,end

def primefac(n):
    l=[]
    while n%2==0:
        l.append(2)
        n=n//2
    p=3
    while p*p<=n:
        while n%p==0:
            l.append(p)
            n=n//p
        p+=2
    if n>2:
        l.append(n)
    return l

def main():
    n,m=[int(k) for k in i().split()]
    l=primefac(n)
    if len(l)<m:
        p("-1\n")
    else:
        fin=[]
        prod=l[0]
        for k in range(1,len(l)-m+1):
            prod*=l[k]
        fin.append(str(prod))
        for k in range(len(l)-m+1,len(l)):
            fin.append(str(l[k]))
        p(" ".join(fin)+"\n")

t=1
#t=int(i())
start=time.perf_counter()
for _ in range(t):
    main()
end=time.perf_counter()
#print(end-start)
#use sys.stdout.write() (remember to convert to str b4 and concatenate "\n") #t=int(i()) #print(end-start)