Ask Your Question
0

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

asked 2020-01-01 15:21:55 +0100

geroyx gravatar image

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 flag offensive close merge delete

Comments

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

Jingenbl gravatar imageJingenbl ( 2020-01-01 16:11:28 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-01-01 16:16:21 +0100

Jingenbl gravatar image

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

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-01-01 15:21:55 +0100

Seen: 730 times

Last updated: Jan 01 '20