# Plentiful interpreter
# written by Keymaker

import sys
import re

if len(sys.argv) < 2:
    print("Error, need a Plentiful program as input.")
    sys.exit()
try:
    f = open(sys.argv[1])
except IOError:
    print("Error in reading the program.")
    sys.exit()
a = f.read().split("\n")
f.close()

m = 2
mc = 1
n = []
cyc = 0
ind = 0

def getfactors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i = i + 1
        else:
            n = n // i
            factors.append(str(i))
    if n > 1:
        factors.append(str(n))
    return factors

i = 0
while i < len(a):
    if len(a[i]) == 0:
        i = i + 1
        continue
    if a[i] == "0":
        print("error: 0 not allowed. [" + str((i+1)) +"]")
        sys.exit()
    r = re.search("^[1-9][0-9]*$", a[i])
    if not r:
        print("error, line '" + a[i] + "' not valid. [" + str((i+1)) + "]")
        sys.exit()
    r = re.findall("^([1-9][0-9]*)$", a[i])
    n.append(int(r[0]))
    i = i + 1
if len(n) < 2:
    print("error, not enough integers defined.")
    sys.exit()

mc = n[0]
n = n[1:]

print("mult: " + str(mc))
print(n)

while 1:
    if ind == 0:
        print("----CYCLE " + str(cyc) + "----")
        cyc = cyc + 1
        m = m * mc
        print("MULT\n" + str(m) + "\n")

    if m % n[ind] == 0:
        print("DIV " + str(n[ind]) + " ok!   [" + str(ind + 1) + "/" + str(len(n)) + "]")
        m = m // n[ind]
        print(m)
    else:
        print("DIV " + str(n[ind]) + " not done   [" + str(ind + 1) + "/" + str(len(n)) + "]")

    ind = (ind + 1) % len(n)

    w = input()
    if w == "q":
        break
    elif w == "f":
        print("prime factorization of " + str(m) + ":")
        print('*'.join(getfactors(m)))
