Problem p03194 (python)

Fixed submission:
import math
import functools
import operator

def prime_factorization_2(num):
    if num <= 1:
        return False
    else:
        num_sqrt = math.floor(math.sqrt(num))
        prime_list = make_prime_list_2(num_sqrt)

        dict_counter = {}
        for prime in prime_list:
            while num % prime == 0:
                if prime in dict_counter:
                    dict_counter[prime] += 1
                else:
                    dict_counter[prime] = 1
                num //= prime
        if num != 1:
            if num in dict_counter:
                dict_counter[num] += 1
            else:
                dict_counter[num] = 1

        return dict_counter

def make_prime_list_2(num):
    if num < 2:
        return []

    # 0のものは素数じゃないとする
    prime_list = [i for i in range(num + 1)]
    prime_list[1] = 0 # 1は素数ではない
    num_sqrt = math.sqrt(num)

    for prime in prime_list:
        if prime == 0:
            continue
        if prime > num_sqrt:
            break

        for non_prime in range(2 * prime, num, prime):
            prime_list[non_prime] = 0

    return [prime for prime in prime_list if prime != 0]



n,p=map(int,input().split())
if n>=p:
    print(1)
elif n==1:
    print(p)
else:
    pdic=prime_factorization_2(p)
    plist=[]
    plsit2=[]
    result=1
    for k in pdic:
        plist.append(k)

    for i in range(len(plist)):
        value=int(pdic[plist[i]])
        if value>=n:
            tmp=value//n
            plsit2.append(plist[i]**tmp)
    for i in plsit2:
        result=result*i        
 
    
    print(result)

Buggy submission (verdict: Runtime Error):
import math
import functools
import operator

def prime_factorization_2(num):
    if num <= 1:
        return False
    else:
        num_sqrt = math.floor(math.sqrt(num))
        prime_list = make_prime_list_2(num_sqrt)

        dict_counter = {}
        for prime in prime_list:
            while num % prime == 0:
                if prime in dict_counter:
                    dict_counter[prime] += 1
                else:
                    dict_counter[prime] = 1
                num //= prime
        if num != 1:
            if num in dict_counter:
                dict_counter[num] += 1
            else:
                dict_counter[num] = 1

        return dict_counter

def make_prime_list_2(num):
    if num < 2:
        return []

    # 0のものは素数じゃないとする
    prime_list = [i for i in range(num + 1)]
    prime_list[1] = 0 # 1は素数ではない
    num_sqrt = math.sqrt(num)

    for prime in prime_list:
        if prime == 0:
            continue
        if prime > num_sqrt:
            break

        for non_prime in range(2 * prime, num, prime):
            prime_list[non_prime] = 0

    return [prime for prime in prime_list if prime != 0]



n,p=map(int,input().split())
if n>=p:
    print(1)
elif n==1:
    print(p)
else:
    pdic=prime_factorization_2(p)
    plist=[]
    plsit2=[]
    for k in pdic:
        plist.append(k)

    for i in range(len(plist)):
        value=int(pdic[plist[i]])
        if value>=n:
            tmp=value//n
            plsit2.append(plist[i]*tmp)
    result = functools.reduce(operator.mul, plsit2)
    print(result)

Buggy submission (verdict: Runtime Error):
import math
import functools
import operator

def prime_factorization_2(num):
    if num <= 1:
        return False
    else:
        num_sqrt = math.floor(math.sqrt(num))
        prime_list = make_prime_list_2(num_sqrt)

        dict_counter = {}
        for prime in prime_list:
            while num % prime == 0:
                if prime in dict_counter:
                    dict_counter[prime] += 1
                else:
                    dict_counter[prime] = 1
                num //= prime
        if num != 1:
            if num in dict_counter:
                dict_counter[num] += 1
            else:
                dict_counter[num] = 1

        return dict_counter

def make_prime_list_2(num):
    if num < 2:
        return []

    # 0のものは素数じゃないとする
    prime_list = [i for i in range(num + 1)]
    prime_list[1] = 0 # 1は素数ではない
    num_sqrt = math.sqrt(num)

    for prime in prime_list:
        if prime == 0:
            continue
        if prime > num_sqrt:
            break

        for non_prime in range(2 * prime, num, prime):
            prime_list[non_prime] = 0

    return [prime for prime in prime_list if prime != 0]



n,p=map(int,input().split())
if n>=p:
    print(1)
elif n==1:
    print(p)
else:
    pdic=prime_factorization_2(p)
    plist=[]
    plsit2=[]
    for k in pdic:
        plist.append(k)

    for i in range(len(plist)):
        value=int(pdic[plist[i]])
        if value>=n:
            tmp=value//n
            plsit2.append(plist[i]*tmp)
result = functools.reduce(operator.mul, plsit2)
print(result)