Problem p02881 (python)

Fixed submission:
N = int(input())
minstep = 9999999999999999999999999999999
for i in range(1, int(N**0.5+1)):
  if N%i == 0:
    minstep = min(minstep, i+N//i-2)
print(minstep)

Buggy submission (verdict: Runtime Error):
N = int(input())
minstep = 9999999999999999999999999999999
for i in range(int(N**0.5+1)):
  if N%i == 0:
    minstep = min(minstep, N+i-2)
print(minstep)

Buggy submission (verdict: Runtime Error):
N = int(input())
outputs = []
for i in range(1, int(N**0.5)):
  if N%i == 0:
    outputs.append(i+N//i-2)
print(min(outputs))

Buggy submission (verdict: Runtime Error):
N = int(input())
for i in range(1, N**0.5):
  if N%i == 0:
    print(i+N//i-2)

Buggy submission (verdict: Runtime Error):
N = int(input())
for i in range(N**0.5):
  if N%i == 0:
    print(i+N//i-2)

Buggy submission (verdict: Runtime Error):

from functools import reduce
from operator import mul
from collections import Counter

def prod(arr):
    return reduce(mul, arr, 1)

def fancy(arr, index):
    output = []
    for i, v in enumerate(index):
        if v:
            output.append(arr[i])
    return output

def prime_factorize(n):
    answers = []
    while n % 2 == 0:
        answers.append(2)
        n //= 2
    f = 3
    while f**2 <= n:  # instead of f <= n**0.5
        if n % f == 0:
            answers.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        answers.append(n)
    return answers

N = int(input())
factors = prime_factorize(N)
counter = Counter(factors)
odd_factors = [factor for factor in factors if counter[factor]%2!=0]
even_factors = [factor for factor in factors if counter[factor]%2==0]

if odd_factors:
    N_odd = prod(odd_factors)
    selectors = [list(map(bool, map(int, list("{0:b}".format(i).zfill(len(odd_factors)))))) for i in range(1, 2**len(odd_factors))]
    even_coeff = prod(even_factors[::2]) if even_coeff else 1
    combinations = [(prod(fancy(factors, selector))*even_coeff, even_coeff*N_odd//prod(fancy(factors, selector))) for selector in selectors]
    
else:
    combinations = [(int(N**0.5), int(N**0.5))]
distances = [combination[0]-1 + combination[1]-1 for combination in combinations]
print(min(distances))

Buggy submission (verdict: Runtime Error):

from functools import reduce
from operator import mul
from collections import Counter

def prod(arr):
    return reduce(mul, arr, 1)

def fancy(arr, index):
    output = []
    for i, v in enumerate(index):
        if v:
            output.append(arr[i])
    return output

def prime_factorize(n):
    answers = []
    while n % 2 == 0:
        answers.append(2)
        n //= 2
    f = 3
    while f**2 <= n:  # instead of f <= n**0.5
        if n % f == 0:
            answers.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        answers.append(n)
    return answers

N=int(input())
factors = prime_factorize(N)
counter = Counter(factors)
odd_factors = [factor for factor in factors if counter[factor]%2!=0]
even_factors = [factor for factor in factors if counter[factor]%2==0]
N_odd = prod(odd_factors)

selectors = [list(map(bool, map(int, list("{0:b}".format(i).zfill(len(odd_factors)))))) for i in range(1, 2**len(odd_factors))]
even_coeff = prod(even_factors[::2])

combinations = [(prod(fancy(factors, selector))*even_coeff, even_coeff*N_odd//prod(fancy(factors, selector))) for selector in selectors]

distances = [combination[0]-1 + combination[1]-1 for combination in combinations]
print(min(distances))

Buggy submission (verdict: Runtime Error):
import numpy as np
from functools import reduce
from operator import mul

def prod(arr):
    return reduce(mul, arr, 1)

def fancy(arr, index):
    output = []
    for i, v in enumerate(index):
        if v:
            output.append(arr[i])
    return output

def prime_factorize(n):
    answers = []
    while n % 2 == 0:
        answers.append(2)
        n //= 2
    f = 3
    while f**2 <= n:  # instead of f <= n**0.5
        if n % f == 0:
            answers.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        answers.append(n)
    return answers

N = int(input())
factors = prime_factorize(N)
selectors = [list(map(bool, map(int, list("{0:b}".format(i).zfill(len(factors)))))) for i in range(1, 2**len(factors))]
combinations = [(prod(fancy(factors, selector)), N//prod(fancy(factors, selector))) for selector in selectors]
distances = [combination[0]-1 + combination[1]-1 for combination in combinations]
print(min(distances))

Buggy submission (verdict: Runtime Error):
import numpy as np


def prime_factorize(n):
    answers = []
    while n % 2 == 0:
        answers.append(2)
        n //= 2
    f = 3
    while f**2 <= n:  # instead of f <= n**0.5
        if n % f == 0:
            answers.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        answers.append(n)
    return answers

N = int(input())
factors = np.array(prime_factorize(N))
counter = Counter(factors)
half = {k:v//2 for k, v in counter.items()}
smaller = np.array([k**v for k, v in half.items()]).prod()
larger = N//smaller
dist = smaller+larger-2
print(dist)