# Arup Guha
# 6/9/2026
# Program to prime factorize integers

# Returns the prime factorization of n as a list of tuple.
def primefact(n):

    # Store list of tuples here.
    res = []

    # Do trial division with i.
    i = 2

    # We can stop at the square root.
    while i*i <= n:

        # Divide out all copies of i.
        exp = 0
        while n%i == 0:
            exp += 1
            n //= i

        # A real term so add it.
        if exp > 0:
            res.append((i,exp))

        # Go to the next one.
        i += 1

    # This might be the last term with the largest prime factor.
    if n > 1:
        res.append((n,1))

    # Return the result.
    return res

# Prints out the prime factorization stored in listprimes.
def printPrimeFact(listprimes):

    # Print out all but the last term.
    for i in range(len(listprimes)-1):
        print("(",listprimes[i][0],"^",listprimes[i][1],")*", sep="", end="")

    # Just the last term without a new multiplication sign at the end.
    print("(",listprimes[-1][0],"^",listprimes[-1][1],")", sep="")

# Test it.
mylist = primefact(293124463416)
printPrimeFact(mylist)
