Problem p02660 (python)

Fixed submission:
N = int(input())
def factorize(n):
    arr = []
    temp = n
    for i in range(2, int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i ==0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr

if N == 1:
    print(0); exit()

f = factorize(N)
ans = 0
for p, i in f:
    j = 0
    while i > j:
        j += 1
        i -= j
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
def factorize(n, already):
    arr = []
    temp = n
    for i in range(2, int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i ==0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 1])

    ret = []
    for a, b in arr:
        for i in range(1, b+1):
            ret.append(a*i)

    ret = set(ret) - set(already)
    return sorted(list(ret))[0]

already = []
z = 0
n = N
ans = 0
for _ in range(100000):
    z = factorize(n, already)
    if z > n or n == 1:
        break
    n = n // z
    already.append(z)
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
def factorize(n, already):
    arr = []
    temp = n
    for i in range(2, int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i ==0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 1])

    ret = []
    for a, b in arr:
        for i in range(1, b+1):
            ret.append(a*i)

    ret = set(ret) - set(already)
    return sorted(list(ret))[0]

already = []
z = 0
n = N
ans = 0
while n >= z:
    if n == 1:
        break
    z = factorize(n, already)
    n = n // z
    already.append(z)
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
def factorize(n, already):
    arr = []
    temp = n
    for i in range(2, int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i ==0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 1])

    ret = []
    for a, b in arr:
        for i in range(1, b+1):
            ret.append(a*i)

    ret = set(ret) - set(already)
    return sorted(list(ret))[0]

already = []
z = 0
n = N
ans = 0
while n >= z:
    z = factorize(n, already)
    n = n // z
    already.append(z)
    ans += 1
    if n == 1:
        break
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
def factorize(n, already):
    arr = []
    temp = n
    for i in range(2, int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i ==0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 1])

    ret = []
    for a, b in arr:
        for i in range(1, b+1):
            ret.append(a*i)

    ret = set(ret) - set(already)
    return list(ret)[0]

already = []
z = 0
n = N
ans = 0
while n >= z:
    z = factorize(n, already)
    n = n // z
    already.append(z)
    ans += 1
    if n == 1:
        break
print(ans)