##### $\mathfrak{Mini}$ $\mathbb{Wiki}$

• No tags, yet
Please remove syntax.php from lib/plugins/nodisp or remove the plugin and reinstall

1. June 2020

# Prime Factorization

This algorithm gives a list in which the all primes multiply together to make the given original number $n$.

#!/usr/bin/python

import math

def primes(n):
p = list()

while n % 2 == 0:
p.append(2)
n>>= 1

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

# if n is a prime
if n > 2:
p.append(n)

return p

Example:

print(primes(127493291))

The primes of $127493291$ are $[193, 647, 1021]$.

print(primes(864))

The primes of $864$ are $[2, 2, 2, 2, 2, 3, 3, 3]$.