How to get the canonical prime factorization, with zero exponents too

Is it possible to get the 'canonical prime factorization', that means to get prime numbers with zero exponents too.
Example:
I have: factor(45) = 3^2 * 5
I need: factor(45) = 2^0 * 3^2 * 5

F = factor(45)
print 'F = factor(45) = ', F
print 'F[0] =', F[0]
print 'F[1] =', F[1]


Out:

F = factor(45) =  3^2 * 5
F[0] = (3, 2)
F[1] = (5, 1)

edit retag close merge delete

something like this:

facteurs = list((410767).factor())

print(facteurs)

[(7, 2), (83, 1), (101, 1)]

solution = facteurs

deja =[p for p,e in facteurs]

for premier in primes(facteurs[0][0]+1,stop=facteurs[-1][0]):

if premier not in deja:

solution.append((premier,0))


print(solution)

[(7, 2), (83, 1), (101, 1), (11, 0), (13, 0), (17, 0), (19, 0), (23, 0), (29, 0), (31, 0), (37, 0), (41, 0), (43, 0), (47, 0), (53, 0), (59, 0), (61, 0), (67, 0), (71, 0), (73, 0), (79, 0), (89, 0), (97, 0)]

happy new year

( 2020-01-01 09:11:28 -0500 )edit

Sort by ยป oldest newest most voted

something like this:

facteurs = list((410767).factor())
print(facteurs)


[(7, 2), (83, 1), (101, 1)]

solution = facteurs
deja =[p for p,e in facteurs]
for premier in primes(facteurs[0][0]+1,stop=facteurs[-1][0]):
if premier not in deja:
solution.append((premier,0))
print(solution)


[(7, 2), (83, 1), (101, 1), (11, 0), (13, 0), (17, 0), (19, 0), (23, 0), (29, 0), (31, 0), (37, 0), (41, 0), (43, 0), (47, 0), (53, 0), (59, 0), (61, 0), (67, 0), (71, 0), (73, 0), (79, 0), (89, 0), (97, 0)]

happy new year

more