Problem p02793 (python)

Fixed submission:
# -*- coding: utf-8 -*-
#グローバル変数
pn_list = [2,3]

def next_pn(pn):
    npn = pn + 2
    pn_flg = 0
    while pn_flg == 0:
        for i in pn_list:
            if npn % i == 0:
                break
            if (i ** 2) > npn:
                pn_flg = 1
                break
        if pn_flg == 1:
            break # 素数が見つかったらbreak
        else:
            npn += 2
    pn_list.append(npn)
    return npn

# 整数の入力
n = int(input())
s = input()
a = [int(x) for x in s.split()]
aa = [int(x) for x in s.split()]

#素数作成
sqr_max_a = int((1.0 * 10**6) ** 0.5) + 1
#sqr_max_a = int(1.0 * 10**6)
pn = 3
while pn < sqr_max_a:
    pn = next_pn(pn)

# a を素因数分解する
lcm = int(1)
for i in pn_list:
    wareta = 1
    while wareta == 1:
        wareta = 0
        for j in range(n):
            if a[j] % i == 0:
                a[j] = a[j] // i
                wareta = 1
        if wareta == 1:
            lcm = lcm * i
pn_lcm = []
for i in a:
    if i > 1:
        if i not in pn_lcm:
            pn_lcm.append(i)
            lcm = lcm * i

min_bsum = int(0)
for i in aa:
    min_bsum = min_bsum + lcm // i

print(min_bsum % (10**9+7))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
#グローバル変数
pn_list = {2:0,3:0}

def next_pn():
    npn = sorted(list(pn_list.keys()))[-1] + 2
    pn_flg = 0
    while pn_flg == 0:
        for i in sorted(list(pn_list.keys())):
            if npn % i == 0:
                break
            if (i ** 2) > npn:
                pn_flg = 1
                break
        if pn_flg == 1:
            break # 素数が見つかったらbreak
        else:
            npn += 2
    pn_list[npn] = 0
    return npn

def check_a(n,a):
    res = "ok"
    for i in range(n):
        if a[i] > 1:
            res = "notyet"
    return res

# 整数の入力
n = int(input())
s = input()
#n = 5
#s ="12 12 12 12 12"
a = [int(x) for x in s.split()]
aa = [int(x) for x in s.split()]

#素数作成
sqr_max_a = int((1.0 * 10**6) ** 0.5) + 1
#sqr_max_a = int(1.0 * 10**6)
pn = 0
while pn < sqr_max_a:
    pn = next_pn()

# a を素因数分解する
pn_lcm = []
for i in pn_list.keys():
    wareta = 1
    while wareta == 1:
        wareta = 0
        for j in range(len(a)):
            if a[j] % i == 0:
                a[j] = a[j] / i
                wareta = 1
        if wareta == 1:
            pn_list[i] += 1
            pn_lcm.append(i)
    if check_a(n,a) == "ok":
        break

for i in a:
    if i > 1:
        pn_lcm.append(i)

min_bsum = int(0)
for i in aa:
    b = 1
    aaa = i
    for j in pn_lcm:
        if aaa % j == 0:
            aaa = aaa / j
        else:
            b = b * j
    min_bsum = min_bsum + b

print(int(min_bsum % (10**9+7)))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
#グローバル変数
pn_list = {2:0,3:0}

def next_pn():
    npn = sorted(list(pn_list.keys()))[-1] + 2
    pn_flg = 0
    while pn_flg == 0:
        for i in sorted(list(pn_list.keys())):
            if npn % i == 0:
                break
            if (i ** 2) > npn:
                pn_flg = 1
                break
        if pn_flg == 1:
            break # 素数が見つかったらbreak
        else:
            npn += 2
    pn_list[npn] = 0
    return npn

def check_a(n,a):
    res = "ok"
    for i in range(n):
        if a[i] > 1:
            res = "notyet"
    return res

# 整数の入力
n = int(input())
s = input()
#n = 3
#s ="1000000 999999 999998"
a = [int(x) for x in s.split()]
aa = [int(x) for x in s.split()]

#素数作成
sqr_max_a = int((1.0 * 10**6) ** 0.5) + 1
#sqr_max_a = int(1.0 * 10**6)
pn = 0
while pn < sqr_max_a:
    pn = next_pn()

# a を素因数分解する
for i in pn_list.keys():
    wareta = 1
    while wareta == 1:
        wareta = 0
        for j in range(len(a)):
            if a[j] % i == 0:
                a[j] = a[j] / i
                wareta = 1
        if wareta == 1:
            pn_list[i] += 1
    if check_a(n,a) == "ok":
        break

lcm = int(1)
for i in pn_list.keys():
    lcm = lcm * (i ** pn_list[i])
for i in a:
    lcm = lcm * i

min_bsum = int(0)
for i in aa:
    min_bsum += lcm / i

print(int(min_bsum % (10**9+7)))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
#グローバル変数
pn_list = {2:0,3:0}

def next_pn():
    npn = list(pn_list.keys())[-1] + 2
    pn_flg = 0
    while pn_flg == 0:
        for i in pn_list.keys():
            if npn % i > 0:
                pn_flg += 1
        if pn_flg == len(pn_list.keys()):
            break # 素数が見つかったらbreak
        else:
            npn += 2
            pn_flg = 0
    pn_list[npn] = 0
    return npn

def check_a(n,a):
    res = "ok"
    for i in range(n):
        if a[i] > 1:
            res = "notyet"
    return res

# 整数の入力
n = int(input())
s = input()
#n = 3
#s ="1000000 999999 999998"
a = [int(x) for x in s.split()]
aa = [int(x) for x in s.split()]

#素数作成
sqr_max_a = int((1.0 * 10**6) ** 0.5) + 1
pn = 0
while pn < sqr_max_a:
    pn = next_pn()

# a を素因数分解する
for i in pn_list.keys():
    wareta = 1
    while wareta == 1:
        wareta = 0
        for j in range(len(a)):
            if a[j] % i == 0:
                a[j] = a[j] / i
                wareta = 1
        if wareta == 1:
            pn_list[i] += 1
    if check_a(n,a) == "ok":
        break

lcm = 1
for i in pn_list.keys():
    lcm = lcm * (i ** pn_list[i])
for i in a:
    lcm = lcm * i

min_bsum = 0
for i in aa:
    min_bsum += lcm / i

print(int(min_bsum % (10**9+7)))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
#グローバル変数
pn_list = {2:0,3:0}

def next_pn():
    npn = list(pn_list.keys())[-1] + 2
    pn_flg = 0
    while pn_flg == 0:
        for i in pn_list.keys():
            if npn % i > 0:
                pn_flg += 1
        if pn_flg == len(pn_list.keys()):
            break # 素数が見つかったらbreak
        else:
            npn += 2
            pn_flg = 0
    pn_list[npn] = 0
    return npn

def check_a(n,a):
    res = "ok"
    for i in range(n):
        if a[i] > 1:
            res = "notyet"
    return res

# 整数の入力
n = int(input())
s = input()
#n = 3
#s ="1000000 999999 999998"
a = [int(x) for x in s.split()]
aa = [int(x) for x in s.split()]

#素数作成
sqr_max_a = int((1.0 * 10**6) ** 0.5) + 1
pn = 0
while pn < sqr_max_a:
    pn = next_pn()

# a を素因数分解する
for i in pn_list.keys():
    wareta = 1
    while wareta == 1:
        wareta = 0
        for j in range(len(a)):
            if a[j] % i == 0:
                a[j] = a[j] / i
                wareta = 1
        if wareta == 1:
            pn_list[i] += 1
    if check_a(n,a) == "ok":
        break

lcm = 1.0
for i in pn_list.keys():
    lcm = lcm * (i ** pn_list[i])

min_bsum = 0.0
for i in aa:
    min_bsum += lcm / i

print(int(min_bsum % (10**9+7)))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
#グローバル変数
pn_list = {2:0,3:0}

def next_pn():
    npn = list(pn_list.keys())[-1] + 2
    pn_flg = 0
    while pn_flg == 0:
        for i in pn_list.keys():
            if npn % i > 0:
                pn_flg += 1
        if pn_flg == len(pn_list.keys()):
            break # 素数が見つかったらbreak
        else:
            npn += 2
            pn_flg = 0
    pn_list[npn] = 0
    return npn

def check_a(n,a):
    res = "ok"
    for i in range(n):
        if a[i] > 1:
            res = "notyet"
    return res

# 整数の入力
n = int(input())
s = input()
a = [int(x) for x in s.split()]
aa = [int(x) for x in s.split()]

#素数作成
sqr_max_a = int((1.0 * 10**6) ** 0.5) + 1
pn = 0
while pn < sqr_max_a:
    pn = next_pn()

for i in pn_list.keys():
    wareta = 1
    while wareta == 1:
        wareta = 0
        for j in range(len(a)):
            if a[j] % i == 0:
                a[j] = a[j] / i
                wareta = 1
        if wareta == 1:
            pn_list[i] += 1
    if check_a(n,a) == "ok":
        break

lcm = 1
for i in pn_list.keys():
    lcm = lcm * i ** pn_list[i]

min_bsum = 0
for i in aa:
    min_bsum += lcm / i

print(int(min_bsum % (10**9+7)))