Problem:


Prime Factorization

Factorize a given integer n.

Input

n

An integer n is given in a line.

Output

Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor.

Constraints

2 ≤ n ≤ 109

Sample Input 1

12

Sample Output 1

12: 2 2 3

Sample Input 2

126

Sample Output 2

126: 2 3 3 7



Sample input:
12


Sample output:
12: 2 2 3

Submission status: Accepted

Solution code:
# 68

def factorization(n):
    ans = []
    _max = int(n ** 0.5 + 1)
    while n % 2 == 0:
        n //= 2
        ans.append(2)
    for i in range(3, _max+1, 2):
        while n % i == 0:
            n //= i
            ans.append(i)
    if n != 1:
        ans.append(n)
    return ans


n = int(input())
ans = factorization(n)

print(n, ": ", sep="", end="")
print(*ans)

Submission status: Accepted

Solution code:
N = int(input())

res = []
x = N
y = 2
while y*y <= x:
    while x % y == 0:
        res.append(y)
        x //= y
    y += 1
if x > 1:
    res.append(x)
print("%d:" % N, *res)

Submission status: Accepted

Solution code:
n = int(input())

a = []
x = n
y = 2
while y*y <= x:
    while x % y == 0:
        a.append(y)
        x //= y
    y += 1
if x > 1:
    a.append(x)
print("%d:" % n, *a)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# モジュールのインポート
import math

# 標準入力を取得
n = int(input())

# 求解処理
ans = []
t = n
while True:
    is_prime = True
    for i in range(2, int(math.sqrt(t)) + 1):
        if t % i == 0:
            ans.append(i)
            t /= i
            is_prime = False
            break
    if is_prime:
        ans.append(t)
        break
ans = map(int, ans)

# 結果出力
print(f"{n}:", " ".join(map(str, ans)))

Submission status: Accepted

Solution code:
n = int(input())
def function(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    
    if n != 1:
        a.append(n)
    
    return a

a = function(n)
print("{0}:" . format(n), end=" ")
for i in range(len(a) - 1):
    print(a[i], end=" ")
print(a[len(a) - 1])

Submission status: Accepted

Solution code:
n = int(input())
def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

if __name__ == '__main__':
    print(n,end=":")
    print("",*prime_factors(n))

Submission status: Accepted

Solution code:
N = int(input())
n = N
ans = []
for i in range(2,int(N**0.5)+1): # intに変換すること
    while(n%i==0):
        n //= i #  整数除算(//)を使うこと
        ans.append(i)
if n!=1:
    ans.append(n)
ans = [str(a) for a in ans]
ans = str(N)+": " + " ".join(ans)
print (ans)

Submission status: Accepted

Solution code:
import math
n = int(input())

x = n
ans = []
i = 2
while i <= math.sqrt(n):
    if n % i == 0:
        n = n //i
        ans.append(str(i))
    else:
        i += 1
if n != 1:
    ans.append(str(n))
print(str(x) + ":" + " " + " ".join(ans))

Submission status: Accepted

Solution code:
import math
n=int(input())
factors=[]
n1=n
p=2
while p<=math.sqrt(n):
    if n%p==0:
        n//=p
        factors.append(str(p))
    else:
        p+=1
if n!=1:
    factors.append(str(n))
print(str(n1)+": "+" ".join(factors))

Submission status: Accepted

Solution code:
def s(n):
    a=[]
    while n%2==0:
        a.append(2)
        n//=2
    f=3
    while f*f<=n:
        if n%f==0:
            a.append(f)
            n//=f
        else:
            f+=2
    if n!=1:
        a.append(n)
    return a
n=int(input())
print(f'{n}: ',end='')
print(*s(n))

Submission status: Accepted

Solution code:
n=int(input())
print(str(n) + ":",end=" ")
x=[]
a=2
while a*a<=n :
    while n%a == 0:
        x.append(a)
        n=n//a
    a+=1
if n>1:
    x.append(n)
print(' '.join(str(k) for k in x))

Submission status: Accepted

Solution code:
def factorization(n):
    L=[]
    temp=n
    print(n,end="")
    print(":",end="")
    for i in range(2,int(n**(1/2)//1)+1):
        if temp%i==0:
            c=0
            while temp%i==0:
                c+=1
                temp//=i
            L.append([i,c])
            for j in range(c):
                print("",i,end="")
    if temp!=1:
        print("",temp,end="")
    
    print()
   
n=int(input())
factorization(n)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

n = int(input())
factors = []

p = 2
m = n
while p*p <= m:
    if m % p == 0:
        factors.append(p)
        m //= p
    else:
        p += 1
if m > 1:
    factors.append(m)

print(f'{n}:', *factors)

Submission status: Accepted

Solution code:
def soinnsuubunnkai(n):
  ret = []
  for i in range(2, int(n ** (1 / 2)) + 1):
    if i > n:break
    while n % i == 0:
      n //= i
      ret.append(i)
  if n != 1:
    ret.append(n)
  return ret

n = int(input())
print(str(n)+": ",end="")
print(*soinnsuubunnkai(n))

Submission status: Accepted

Solution code:
i = 2
n = int(input())
n_ = n

ans = []

while i*i <= n:
    while n % i == 0:
        ans.append(i)
        n //= i
    i += 1

if n > 1:
    ans.append(n)

print(str(n_) + ': ' + ' '.join([str(i) for i in ans]))

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def prime_factorize(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr


def main():
    N = int(readline())
    prime = prime_factorize(N)
    ans = str(N) + ':'
    for i, k in prime:
        ans += ' {}'.format(i) * k
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
b=prime_factorize(n) 
print(f'{n}: ',end="")
print(*b)

Submission status: Accepted

Solution code:
def factorization(n):
    L=[]
    temp=n
    print(n,end='')
    print(':',end='')
    for i in range(2,int(n**(1/2)//1)+1):
        if temp%i==0:
            c=0
            while temp%i==0:
                c+=1
                temp//=i
            L.append([i,c])
            for j in range(c):
                print('',i,end='')
                
    if temp!=1:
        print('',temp,end='')
    print()
        
n=int(input())
factorization(n)

Submission status: Accepted

Solution code:
def prime_fact(n):
    ret = []
    if n == 1:
        return [1]
    for d in [2] + list(range(3, int(n ** 0.5) + 1, 2)):
        while n % d == 0:
            ret.append(d)
            n //= d
    if n != 1:
        ret.append(n)
    return ret

n = int(input())
print("{}: ".format(n), end = "")
print(*prime_fact(n))

Submission status: Accepted

Solution code:
n = int(input())
p = 2
count = []

print('{}:'.format(n), end = ' ')

while p*p  <= n: 
    while n%p == 0: 
        n = n//p
        count.append(p)
    p += 1


if not n == 1:
     count.append(n)

print(*count)

Submission status: Accepted

Solution code:
n = int(input())
m = str(n) + ":"
a = True
l = n
i = 2
while a:
  if l % i == 0:
    l /= i
    m += ' ' + str(i)
    i -= 1
  a = i < l**0.5
  i += 1
if l != 1:
  m += ' ' + str(int(l))
print(m)

Submission status: Accepted

Solution code:
num=int(input())
print(str(num)+': ',end='')
i=2
a=[]
while i*i  <= num:
    while num % i == 0:
        num //= i
        a.append(i)
    i += 1
if num != 1:
    a.append(num)
    
print (*a)

Submission status: Accepted

Solution code:
#73 素因数分解

import math
n = int(input())

a = n
ans = []
i = 2
while i <= math.sqrt(n):
    if n % i == 0:
        n = n //i
        ans.append(str(i))
    else:
        i += 1
if n != 1:
    ans.append(str(n))
print(str(a) + ":" + " " + " ".join(ans))

Submission status: Accepted

Solution code:
n=input()
print(n+': ',end='')
n=int(n)
x = 2
ans = []
while x * x <= n:
    while n % x == 0:
        n //= x
        ans.append(x)
    x = x + 1
if n > 1:
    ans.append(n)
print(" ".join(list(map(str, ans))))

Submission status: Accepted

Solution code:
def factorization(n):
    L=[]
    temp=n
    print(n,end="")
    print(":",end="")
    for i in range(2, int(n**(1/2)//1)+1):
        if temp%i==0:
            c=0
            while temp%i==0:
                c+=1
                temp//=i
            L.append([i, c])
            for j in range(c):
                print("",i,end="")
    if temp!=1:
        print("",temp,end='')
    if L==[]:
        pass
    print()
    return L
n=int(input()) 
factorization(n)

Submission status: Accepted

Solution code:
def factorization(n):
    L=[]
    temp=n
    print(n,end="")
    print(":",end="")
    for i in range(2, int(n**(1/2)//1)+1):
        if temp%i==0:
            c=0
            while temp%i==0:
                c+=1
                temp//=i
            L.append([i, c])
            for j in range(c):
                print("",i,end="")
    if temp!=1:
        print("",temp,end='')
    print()
    return L
n=int(input()) 
factorization(n)

Submission status: Accepted

Solution code:
n = int(input())
m = n
result = []

for i in range(2, n+1):
    
    while m%i==0:
        m = m//i
        result.append(i)
        
    if m==1:
        break
        
    if i>n**(1/2) and m==n:
        result.append(n)
        break

print(str(n)+':', *result)

Submission status: Accepted

Solution code:
def factor(n):
    a=[]
    suu=n
    for i in range(2,int(n**0.5//1)+1):
        if suu%i==0:
            sosuu=0
            while suu%i==0:
                sosuu+=1
                suu//=i
            for j in range(sosuu):
                a.append(i)
    if suu!=1:
        a.append(suu)
    print(n,end='')
    print(':',*a)
n=int(input())
factor(n)

Submission status: Accepted

Solution code:
def factorization(n):
   y=n
   list=[]
   print(n, end=":")
   for i in range(2,int(n**(1/2)//1)+1):
      if y%i==0:
         c=0
         while y%i==0:
            c += 1
            y=y//i
         list.append([i, c])
         for j in range(c):
            print("", i, end="")
   if y!=1:
      print("", y, end="")
   print()
n=int(input())
factorization(n)

Submission status: Accepted

Solution code:
def factorization(n):
    L=[]
    temp=n
    print(n,end="")
    print(":",end="")
    for i in range(2, int(n**(1/2)//1)+1):
        if temp%i==0:
            c=0
            while temp%i==0:
                c+=1
                temp//=i
            L.append([i, c])
            for j in range(c):
                print("",i,end="")
                

    if temp!=1:
        print("",temp,end="")

    print()

n=int(input()) 
factorization(n)

Submission status: Accepted

Solution code:
def factorization(n):
    L=[]
    temp=n
    print(n,end="")
    print(":",end="")
    for i in range(2, int(n**(1/2)//1)+1):
        if temp%i==0:
            c=0
            while temp%i==0:
                c+=1
                temp//=i
            L.append([i, c])
            for j in range(c):
                print("",i,end="")
    if temp!=1:
        print("",temp, end="")
    print()
n=int(input()) 
factorization(n)

Submission status: Accepted

Solution code:
n = int(input())
num = n

fct = []
cur = 2
while cur * cur <= n:
    while n % cur == 0:
        n //= cur
        fct.append(cur)
    cur += 1
if n > 1:
    fct.append(n)

print(str(num) + ": " + ' '.join(str(f) for f in fct))

Submission status: Accepted

Solution code:

n=int(input())
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

x=factorize(n)
L=[str(a) for a in x]
L=" ".join(L)
print(f'{n}: {L}')

Submission status: Accepted

Solution code:
n=int(input())
a=2
s=[]
N=n
while a*a<=n:
    while n%a==0:
        n//=a
        s.append(str(a))
    a+=1
if n>1:
    s.append(str(n))
print(str(N) + ": " + " ".join(s))

Submission status: Accepted

Solution code:
n = int(input())
b = n
a = []

while n % 2 == 0:
    a.append(2)
    n //= 2
f = 3
while f * f <= n:
    if n % f == 0:
        a.append(f)
        n //= f
    else:
        f += 2
if n != 1:
    a.append(n)
    
print(f'{b}:',*a)

Submission status: Accepted

Solution code:
n = int(input())
m = int(n**0.5)+2
is_prime = [1]*m
is_prime[0] = is_prime[1] = 0
for p in range(2,m):
    for q in range(2*p,m,p):
        is_prime[q] = 0
primes = [p for p, c in enumerate(is_prime) if c]

print(str(n)+': ', end='')
ans = []
for p in primes:
    while n % p == 0:
        ans.append(p)
        n //= p
if n > 1:
    ans.append(n)
print(*ans)

Submission status: Accepted

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

import math

n = ii()


def calc(x):
    nq = int(math.sqrt(x)+1)
    for i in range(2,nq +1):
        if x % i == 0:
            return x//i, i
    return -1,x

x = n
ans = []
while 1:
    x,m = calc(x)
    ans.append(m)
    if x <= 1:
        break
    

print(str(n)+': ',end='')
print(*ans)

Submission status: Accepted

Solution code:
n=int(input())
nc=n
out=[]

while n%2==0:
    out.append(2)
    n//=2

for i in range(3,int(n**0.5)+1,2):
    if n==1 : break
    while n%i==0:
        out.append(i)
        n//=i

if n!=1 : out.append(n)

print("{}: {}".format(nc," ".join(map(str,out))))

Submission status: Accepted

Solution code:
def prime_factorize(n):
    ans = []
    while True:
        if n % 2 == 0:
            ans.append(2)
            n //= 2
        else:
            break
    div = 3

    while div*div <= n:
        if n % div == 0:
            ans.append(div)
            n //= div
        else:
            div += 2

    if n != 1:
        ans.append(n)

    return ans


def eratosthenes_shieve(n):
    is_prime = [True for i in range(n+1)]
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n+1):
        if not is_prime[i]:
            continue
        for j in range(i*2, n+1, i):
            is_prime[j] = False
    
    return [i for i in range(len(is_prime)) if is_prime[i]]


def eratosthenes_shieve_pf(n):
    primes = eratosthenes_shieve(int(n**0.5)+1)
    ans = []
    for p in primes:
        while n % p == 0:
            ans.append(p)
            n //= p

    if n != 1:
        ans.append(n)

    return ans


def main():
    n = int(input())
    # ans = prime_factorize(n)
    ans = eratosthenes_shieve_pf(n)
    s = "{}: ".format(n)
    for i in ans:
        s += str(i) + " "
    print(s[:-1])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
num = n
A = []
b = 2
while b*b <= n:
    while n % b == 0:
        n //= b
        A.append(b)
    b += 1
if n > 1:
    A.append(n)
print(str(num)+": "+' '.join(str(f) for f in A))

Submission status: Accepted

Solution code:
import math
def soi(x):
    y = x
    a = []
    for i in range(2,int(math.sqrt(x))+1):
        while x%i == 0:
            a.append(i)
            x/=i
    if len(a)==0 or x!=1:
        a.append(int(x))
    a.sort()
    print(str(y)+':',*a)

n = int(input())
soi(n)

Submission status: Accepted

Solution code:
n = int(input())
n1 = n
a = 2
x = []
while a*a <= n:
    while n % a == 0:
        n //= a
        x.append(str(a))
    a += 1
if n > 1:
    x.append(str(n))
print(str(n1) + ": " + " ".join(x))

Submission status: Accepted

Solution code:
import math
n = int(input())


def prime_factorization(num):
    sqrt_num = math.sqrt(num)
    prime_numbers = []
    for i in range(2, int(sqrt_num) + 1):
        # print(num)
        while num % i == 0:
            # print(num)
            num = num / i
            prime_numbers.append(i)
    if num != 1:
        prime_numbers.append(int(num))
    return prime_numbers


print(str(n) + ":", *prime_factorization(n))

Submission status: Accepted

Solution code:
import math

N = int(input())
divided = N
prime_factor = []

for i in range(2, int(math.sqrt(N)//1)+1):
  while divided%i == 0:
      prime_factor.append(i)
      divided //= i
if divided != 1:
  prime_factor.append(divided)

print("{}: ".format(N, *prime_factor), end="")
print(*prime_factor)

Submission status: Accepted

Solution code:
n=int(input())
i=2
a=[str(n)+':']
m=n
while n>1:
  if i>m**.5:
    a.append(n)
    break
  if n%i==0:
    n//=i
    a.append(i)
  else:i+=1  
print(*a)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def prime_factorization(n):
    """
    nを素因数分解します
    """
    res = []
    for i in range(2, int(pow(n, 0.5)) + 1):
        if n % i == 0:
            ex = 0
            while n % i == 0:
                ex += 1
                n //= i
            res.append([i, ex])
    if n != 1:
        res.append([n, 1])

    return res


def resolve():
    n = int(input())
    prime = prime_factorization(n)

    res = []
    for p, ex in prime:
        for _ in range(ex):
            res.append(p)
    print(str(n) + ":", *res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
def prime_factorize(n):
    l = []
    s = '{}:'.format(n)
    i = 2
    while i * i <= n:
        while n % i == 0:
            l.append(i)
            n //= i
        i += 1
    if n != 1:
        l.append(n)
    for i in l:
        s += ' {}'.format(i)
    return s


if __name__ == '__main__':
    print(prime_factorize(int(input())))

Submission status: Accepted

Solution code:
def factorize(n):
  i = 2
  m = n
  factors = []
  
  while i*i <= m:
    if m%i==0:
      m //= i
      factors.append(i)
    else:
      i += 1

  if m > 1:
    factors.append(m)

  return factors

n = int(input())
primes = factorize(n)
print("{0}: {1}".format(n, " ".join(list(map(str,primes)))))

Submission status: Accepted

Solution code:
import math
import copy
n = int(input())
ncopy = copy.deepcopy(n)
ans = []
while True:
    if n % 2 == 1:
        break
    ans.append(str(2))
    n //= 2
i = 3
while True:
    if i**2 > n:
        break
    if n % i == 0:
        ans.append(str(i))
        n //= i
    else:
        i += 2
if n != 1:
    ans.append(str(n))
print(str(ncopy)+": "+(" ".join(ans)))

Submission status: Accepted

Solution code:
x=n=int(input())
a=[]
while n%2==0:
    a.append(2)
    n=n//2
m=3
while m*m<=n:
    if n%m==0:
        a.append(m)
        n=n//m
    else:
        m+=2
if n!=1:
    a.append(n)
b=''
for i in range(len(a)):
    b=b+' '+str(a[i])
    i+=1
print(str(x)+':'+b)

Submission status: Accepted

Solution code:
import math
n=int(input())
k=n
i=2
l=[]
while i**2<=n:
    while n%i==0:
        n//=i
        l.append(i)
    i+=1
if n>1:
    l.append(n)

print(k,end="")
print(":",*l)

Submission status: Accepted

Solution code:
n=n1=int(input())
k=int(n**0.5)
a=[]

while n%2==0:
    a.append(2)
    n=n/2

for i in range(3, k, 2):
    while n%i==0:
        a.append(i)
        n=int(n/i)

    if n==1:
        break
    if i*i>n:
        break

if n!=1:
    a.append(n)

print(n1,":",sep="", end="")

for i in range(len(a)):
    print(" ", end="")
    print(a[i], end="")

print("")

Submission status: Accepted

Solution code:
#NTL_1_A
l = []
f = 3
n = int(input())
print(n,end='')
print(':',end=' ')
while n%2 == 0:
    l.append(2)
    n = n//2
while f <= n**(1/2):
    if n%f == 0:
        l.append(f)
        n = n//f
    else:
        f += 2
if n != 1:
    l.append(n)

print(' '.join(map(str,l)))

Submission status: Accepted

Solution code:
# coding: utf-8
# 73
n = int(input())
def prime_factorize(n):
    a=[]
    while n%2 == 0:
        a.append(2)
        n //= 2
    f=3
    while f*f <= n:
        if n%f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

print(n,end='')
print(':',end=' ')
print(*prime_factorize(n))

Submission status: Accepted

Solution code:
n=input()
print(n+': ',end='')
n=int(n)
x = 2
ans = []
while x * x <= n:
    while n % x == 0:
        n //= x
        ans.append(x)
    x = x + 1
if n > 1:
    ans.append(n)
print(" ".join(list(map(str, ans))))

Submission status: Accepted

Solution code:
import math
n = int(input())
pri  = [str(n)+":"]

i = 2
while i <= math.sqrt(n):
    while n % i == 0:
        pri.append(str(i))
        n//=i
    i+=1

if n != 1:
    pri.append(str(n))

L=[str(pri) for pri in pri]
L=" ".join(L)
print(L)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())
ans = '{}:'.format(n)

prime_factors = []
i = 2
while i ** 2 <= n:
    ext = 0
    while n % i == 0:
        ext += 1
        n //= i
    if ext:
        prime_factors.append((i, ext))
    i += 1

if n != 1:
    prime_factors.append((n, 1))

for pf, num in prime_factors:
    ans = '{} {}'.format(ans, ' '.join([str(pf)] * num))

print(ans)

Submission status: Accepted

Solution code:
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
N = int(input())
ans = map(str,sorted(prime_factorize(N)))
print(str(N)+': '+' '.join(ans))

Submission status: Accepted

Solution code:
import math
n = int(input())
a = []
b = n
for i in range(2,int(math.sqrt(n+1))+10):
    while b % i == 0:
        b //= i
        a.append(i)
    
if b != 0 and b != 1:
    a.append(b)

    
print(n,end='')
print(': ',end='')
print(*a)

Submission status: Accepted

Solution code:
def prime(n):
    a=[]
    while n%2 == 0:
        a.append(2)
        n //= 2
    f=3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
n=int(input())
r=prime(n)
R=map(str,r)
u=' '.join(R)
print("{}: {}".format(n,u))

Submission status: Accepted

Solution code:
import math
n = int(input())

def factorize_rec(n, factor):
    for i in range(2, math.floor(math.sqrt(n)) + 1):
        if n % i == 0:
            factor.append(i)
            return factorize_rec(n/i, factor)
    factor.append(int(n))
    return factor

def factorize(n):
    return factorize_rec(n, [])

print(str(n) +":", end=" ")
# for i in factorize(n):
#     print(i, end=" ")
print(*factorize(n), sep=' ')

Submission status: Accepted

Solution code:
n = int(input())

def factorize(n: int) -> list:
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

print(f'{n}:', *(factorize(n)))

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(input())
n = N

ans = defaultdict(int)
i = 2
while i ** 2 <= n:
    count = 0
    while n > 1:
        if n % i != 0:
            break
        n //= i
        count += 1
    if count > 0:
        ans[i] = count
    i += 1
if n > 1:
    ans[n] = 1
print(str(N) + ':', end="")
for i, count in ans.items():
    for j in range(count):
        print(" ", end="")
        print(i, end="")
print()

Submission status: Accepted

Solution code:
#refer https://onlinejudge.u-aizu.ac.jp/solutions/problem/NTL_1_A/review/2821138/vjudge2/Python3
def prime_factorize(n):
    res = []
    a = 2
    while a*a <= n:
        if n % a == 0:
            while n % a == 0:
                n //= a
                res.append(str(a))
        a += 1
    
    if n != 1:
        res.append(str(n))

    return res

n = int(input())
ans = prime_factorize(n)

print(str(n) + ": " + " ".join(ans))

Submission status: Accepted

Solution code:
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
n=int(input())
l=factorization(n)
ans=[]
for item in l:
    a=item[0]
    b=item[1]
    for i in range(b):
        ans.append(str(a))
print(str(n)+": "+" ".join(ans))

Submission status: Accepted

Solution code:
n = int(input())

# n<= 10**9なので、高速化する
# 約数列挙でroot N に抑えるか？
def prime_divide(n):
    res = []
    i = 2
    while True:
        if n % i == 0:
            res.append(i)
            n //= i
        else:
            i += 1
            if i > n ** (0.5):
                break
    if n != 1:
        res.append(n)
    return res


print(n, end="")
print(":", *prime_divide(n))

Submission status: Accepted

Solution code:
import math
n=int(input())
print(str(n)+":",end=" ")

ans=[]
i=2
while i<=math.sqrt(n):
    if n%i==0:
        ans.append(i)
        n=n//i
    else:
        i+=1
ans.append(n)
print(*ans)

Submission status: Accepted

Solution code:
n = int(input())
tmp = n
fact =  []
for i in range(2,int(-(-n**0.5//1))+1):
    while tmp%i == 0:
            fact.append(str(i))
            tmp //= i
            
if tmp != 1:
    fact.append(str(tmp))

#print(fact)
            
print(str(n) + ': ' + " ".join(fact))

Submission status: Accepted

Solution code:
n=int(input())
m=n
ans=[]
for i in range(2,int(n**0.5)+1):
  while n % i == 0:
    ans.append(i)
    n //= i
if n != 1:
  ans.append(n)
l=str(m)+":"
print(l," ".join(map(str,ans)))

Submission status: Accepted

Solution code:
import math

def prime_factorization(n):
    factors = []
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            while True:
                factors.append(i)
                n //= i
                if n % i != 0: break
    if n > 1:
        factors.append(n)
    return factors

n = int(input())
factors = prime_factorization(n)
print(f'{n}:', *factors)

Submission status: Accepted

Solution code:
from math import sqrt

n = int(input())

out = [str(n) + ":"]

for i in range(2, int(sqrt(n)) + 1):
    while n % i == 0:
        n //= i
        out.append(str(i))

if n != 1 and n not in out:
    out.append(str(n))

print(" ".join(out))

Submission status: Accepted

Solution code:
# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append('2')
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(str(f))
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(str(n))
    return a

def main():
    n = int(input())
    ans = prime_factorize(n)
    print(str(n) + ': ' + ' '.join(ans))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_A&lang=ja

def prime_factors(n):       # 戻り値はiterable type
    i = 2
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            yield i
    if n > 1:
        yield n

N = int(input())

P = list(prime_factors(N))     # 素因数のリスト


print(str(N) + ":", *P)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

"""Compute the prime factorization of the given integer by trial division.

Verification: [NTL_1_A](https://example.com)
"""

import math


def factorize_trial_division(n):
    """Compute the prime factorization of the given integer `n` by trival division.

    Returns: the prime factors as a list.
    """
    factors = []
    if n < 2:
        return factors
    for p in range(2, math.ceil(math.sqrt(n)) + 1):
        if p * p > n:
            break
        while n % p == 0:
            factors.append(p)
            n //= p
    if n > 1:
        factors.append(n)
    return factors


def main():
    n = int(input())
    fs = factorize_trial_division(n)
    print("{}:".format(n), *fs)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n = int(input())
print(str(n)+':', ' '.join([str(i) for i in factorize(n)]))

Submission status: Accepted

Solution code:
n = int(input())

def pfact(m):
	pf = {}
	for i in range(2,int(m**0.5)+1):
		while m%i == 0:
			pf[i] = pf.get(i,0) + 1
			m //= i
	if m>1 : pf[m]=1
	return pf

ansl = [f"{n}:"]
for i, j in pfact(n).items():
	for _ in range(j):
		ansl.append(str(i))
print(" ".join(ansl))

Submission status: Accepted

Solution code:
n=int(input())
m=n
lst=[]
while n%2==0:
    lst.append(2)
    n//=2
f=3
while f*f<=n:
    if n%f==0:
        lst.append(f)
        n//=f
    else:
        f+=2
if n!=1:
    lst.append(n)
print("{}:".format(m),*lst)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    def factorization(n):
        arr = []
        tmp = n
        # √nまでを調べればいい
        for i in range(2, int(-(-tmp**0.5//1))+1):
            if tmp%i == 0:
                cnt = 0
                # 割れる場合は割れなくなるまで同じ数でわる
                while tmp%i == 0:
                    cnt += 1
                    tmp //= i
                    arr.append(i)
        # 最後1になるか素数が余るので素数ならリストに追加
        if tmp != 1:
            arr.append(tmp)
        # そもそも
        if arr == []:
            arr.append(n)
        return arr
    res = factorization(n)
    print(str(n)+': ', end='')
    for i in range(len(res)-1):
        print(res[i], end=' ')
    print(res[len(res)-1])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
factors = []
import math
sqrt = math.floor(n ** 0.5)
z = n
for i in range(2, sqrt + 1):
    if not z % i:
        while z % i == 0:
            factors.append(i)
            z //= i
if z > 1:
    factors.append(z)
print('{}:'.format(n), *factors)

Submission status: Accepted

Solution code:
n=input()
print(n+': ',end='')
n=int(n);d=2
while n%d==0 and n>3:
    print(d,end=' ')
    n//=d
d+=1
m=n//d
while m>=d:
    if(n%d==0):
        print(d,end=' ')
        n=m
    else:d+=2
    m=n//d
print(n)

Submission status: Accepted

Solution code:
origin_n=int(input())
n=origin_n
dpair=[]
for i in range(2,int(n**(1/2))+1):
	k=0
	while True:
		if n//i == n/i:
			k+=1
			n/=i
		else:
			break
	if k!=0:
		dpair.append([i,k])

if n!=1:
	dpair.append([int(n),1])
print(f"{origin_n}:",end="")

for i in dpair:
	for k in range(i[1]):
		print(f" {i[0]}",end="")
print()

Submission status: Accepted

Solution code:
def prime_factorization(n):
    l = []
    i = 2
    while i * i <= n:
        if n % i == 0:
            n //= i
            l.append(i)
        else:
            i += 1
    if n > 1:
        l.append(n)
    return l


if __name__ == '__main__':
    n = int(input())
    ans = str(n) +  ':'
    ret = prime_factorization(n)
    for e in ret:
        ans += f' {e}'
    print(ans)