Python prime factorization

Asked 1 weeks ago, Updated 1 weeks ago, 1 views

That's the problem at the top, and that's the code I wrote at the bottom. If you print it out like this, only the prime factor comes out, so can you tell me how to express it as an exponent and a product like the output example?

python

2022-09-20 14:38

1 Answers

num = int(input())
p = 2
if num == 1:
    print("error")
else:
    while True:
        c = 0
        while num % p == 0:
            num = num // p
            c += 1
        if c:
            print(f"{p}^{c}", end="")
            if num == 1:
                break
            print(" X ", end="")
        p += 1

if num%count == 0 Replace this part with while and count the number of times.


2022-09-20 14:38

If you have any answers or tips


© 2022 pinfo. All rights reserved.