Problem:


Score : 300 points

Problem Statement

Takahashi is standing on a multiplication table with infinitely many rows and columns.

The square (i,j) contains the integer i \times j. Initially, Takahashi is standing at (1,1).

In one move, he can move from (i,j) to either (i+1,j) or (i,j+1).

Given an integer N, find the minimum number of moves needed to reach a square that contains N.

Constraints

2 \leq N \leq 10^{12}

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the minimum number of moves needed to reach a square that contains the integer N.

Sample Input 1

10

Sample Output 1

5

(2,5) can be reached in five moves. We cannot reach a square that contains 10 in less than five moves.

Sample Input 2

50

Sample Output 2

13

(5, 10) can be reached in 13 moves.

Sample Input 3

10000000019

Sample Output 3

10000000018

Both input and output may be enormous.



Sample input:
10


Sample output:
5

Submission status: Runtime Error

Solution code:
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))

Submission status: Runtime Error

Solution code:
import sys
import math
ab = []
abc= []
def divisor(n):
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ab.append(i)
            if i**2 == n:
                continue
            abc.append(n//i)
a = input()
a = int(a)
divisor(a)
abcd = []
k = 0
#print(ab)
#print(abc)
for _ in range(len(ab)-1):
  abcd.append(int(ab[k])+int(abc[k]))
  k = k+1 
d = abcd.index(min(abcd))
#print(abcd)
#print(ab)
#print(abc)
#print(d)
print(ab[d]+abc[d]-2)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N=int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

ans=make_divisors(N)

temp=ans[0]+ans[1]-2

for i in range(len(ans)):
    if i%2!=0:
        continue
    if temp>ans[i]+ans[i+1]-2:
        temp=ans[i]+ans[i+1]-2
print(temp)

Submission status: Runtime Error

Solution code:
def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

N = int(input())
stack = []
if is_prime(N):
    stack.append(N+1)
else:
    for i in range(1, N//2):
        for j in range(1, N//2):
            if i*j == N:
                stack.append(i+j)

stack.sort()
print(stack[0] - 2)

Submission status: Runtime Error

Solution code:
from functools import reduce
from operator import mul
N = int(input())
divide = []
for i in range(2,int( (10**12) ** (1/ 2) ) + 1):
    while( N % i == 0):
        divide.append(i)
        N = int( N/i )
    if N ==1:
        break

i = 0
check = []
while(i < len(divide)-1):
    a = divide[:i+1]
    x = reduce(mul,a)
    b = divide[i+1:]
    y = reduce(mul,b)
    check.append(x + y)
    i += 1
    
ans = min(check) - 2
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import os
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

N = int(input())
listN = make_divisors(N)
mini = 10**12
if len(listN) == 1:
    x = N
    y = 1
else:
    for i in range(0,len(listN),2):
        x = listN[i]
        y = listN[i+1]
        mini = min(x+y,mini)
print(x-1+y-1)

Submission status: Runtime Error

Solution code:
n = int(input())

a = []
if n%2==0:
    if n // 10000 >= 1:
        for i in range(1, n//10000):
            q, mod = divmod(n, i)
            if mod == 0:
                a.append((i,q))
    
        max = max(a)
        print(sum(max)-2)
    
    else:
        for i in range(1, n//2):
            q, mod = divmod(n, i)
            if mod == 0:
                a.append((i,q))
    
        max = max(a)
        print(sum(max)-2)

else:
    print(n-1)

Submission status: Runtime Error

Solution code:
import sys,math
def input():
    return sys.stdin.readline()[:-1]


a,b,x = map(int,input().split(' '))

t = x/(a**2)
half = b/2
if t<half:
    a_2 = x/b
    b_2 = b
else:
    a_2 = a
    b_2 = (b-t)*2
c = (a_2**2+b_2**2)**0.5
cos1 = ((a_2**2)+(c**2)-(b_2**2))/(2*a_2*c)
print(math.degrees(math.acos(cos1)))

Submission status: Runtime Error

Solution code:
from math import ceil, sqrt
N = int(input())

for i in range(floor(sqrt(N)), 0, -1):
    if N % i == 0:
        print((N//i) + i - 2)
        break

Submission status: Runtime Error

Solution code:
from functools import reduce
from operator import mul
N = int(input())
divide = []
for i in range(2,int( (10**12) / 2 ) + 1):
    while( N % i == 0):
        divide.append(i)
        N = int( N/i )
    if N ==1:
        break

i = 0
check = []
while(i < len(divide)-1):
    a = divide[:i+1]
    x = reduce(mul,a)
    b = divide[i+1:]
    y = reduce(mul,b)
    check.append(x + y)
    i += 1
    
ans = min(check) - 2
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
n = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
list = make_divisors(n)
root = int(n**0.5)+1
for i in range(len(list)-1):
    if (list[i] <= root and list[i+1] >root):
        a= list[i]
if n == 1:
    a=1
b = n //a
print(a+b-2)

Submission status: Runtime Error

Solution code:
N = int(input())
ans = []
for i in range(1,(N//2)+1):
  for j in range(1,(N//2)+1):
    cnt=0
    if i*j==N:
      cnt +=i-1
      cnt +=j-1
      ans.append(str(cnt))
ans=min(ans)
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
n = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
list = make_divisors(n)
root = int(n**0.5)+1
for i in range(len(list)):
    if (list[i] <= root and list[i+1] >root):
        a= list[i]
b = n //a
print(a+b-2)

Submission status: Runtime Error

Solution code:
A = int(input())

for i in range(2,A):
  if (A % i == 0):
    a = i
    break

b = A / a
print(int(a+b-2))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
from sympy.ntheory import factorint
import numpy as np


def solve(N: int):

    fct = factorint(N)

    fct_list = []
    for key, item in zip(fct.keys(), fct.values()):
        fct_list += [key] * item

    result = 1e12

    if len(fct_list) == 2:
        x = fct_list[0]
        y = fct_list[1]
        print(x - 1 + y - 1)
    elif len(fct_list) == 1:
        x = fct_list[0]
        y = 1
        print(x - 1 + y - 1)

    else:
        for i in range(1, len(fct_list) - 1):

            x = np.prod(fct_list[: i + 1])
            y = np.prod(fct_list[i + 1 :])

            result = min(result, x - 1 + y - 1)
        print(result)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import math

N = int(input())

tmp = []
for i in range(1,500):
    if N % i == 0:
        tmp.append((i, N//i))

res = math.inf
for i, x in tmp:
    Min =  (i-1) + (x-1)
    if res > Min:
        res = Min

print(res)

Submission status: Runtime Error

Solution code:
import math

c = list(map(float, input().split()))
a = c[0]
b = c[1]
x = c[2]
if x <= a * a * b / 2.0:
  print(90.0 - math.atan((x / a * 2.0 / b) / b) * 180.0 / math.pi)
else:
  print(math.atan(((a * a * b - x) / a * 2.0 / a) / a) * 180.0 / math.pi)

Submission status: Runtime Error

Solution code:
n = int(input())
ans = []
for i in range(1,int(n**0.5)):
    if n%i==0:
        ans.append(i-1+((n//i)-1))
print(min(ans))

Submission status: Runtime Error

Solution code:

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
  
def prod(n):
  result = 1
  for x in n:
    result *= x
  return result
  
a = prime_factorize(n)
b = [a.pop(-1)]


while prod(a) > prod(b):
  prev_result = prod(a) + prod(b)
  b.append(a.pop(0))

try:
  if prev_result < prod(a) + prod(b):
    a.append(b.pop(-1))

except:
  pass
print(prod(a)-1 +prod(b)-1)

Submission status: Runtime Error

Solution code:
n = int(input())

a = []
if n%2==0:
    for i in range(1, n//2):
        q, mod = divmod(n, i)
        if mod == 0:
            a.append((i,q))
    
    max = max(a)

    print(sum(max)-2)
else:
    print(n-1)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
ans = []
for i in range(1,int(math.sqrt(n))):
    if n%i==0:
        ans.append(i-1+((n//i)-1))
print(min(ans))

Submission status: Runtime Error

Solution code:
N=int(input())
ans=[0]*N
for i in range(1,N+1):
    if N%i==0:
        ans[i-1]=i
while 0 in ans :
    ans.remove(0)
ansN=[0]*len(ans)
for j in range(len(ans)):
    ansN[j]=int(N/ans[j])-1+ans[j]-1
print(min(ansN))

Submission status: Runtime Error

Solution code:
import math
N = int(input())
if isPrime(N):
  print(N - 1)
else:
  x = math.floor(N**(0.5))
  for i in range(x,N+1):
    if N%i == 0:
      print(N//i + i -2)
      break

Submission status: Runtime Error

Solution code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
  
n = int(input())
d = make_divisors(n)
d.sort()
a = []
for i in range(len(d)-1):
  if d[i]**2==n:
    a.append(d[i], d[i])
    continue
  for j in range(i+1, len(d)):
    if d[i] * d[j] == n:
      a.append([d[i], d[j]])
      break
m = n
ind = 0
for i in a:
  if abs(i[0]-i[1]) < m:
    m = abs(i[0]-i[1])
    ind = a.index(i)

print(a[ind][0]+a[ind][1]-2)

Submission status: Runtime Error

Solution code:

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
  
def prod(n):
  result = 1
  for x in n:
    result *= x
  return result
  
a = prime_factorize(n)
b = [a.pop(-1)]

while prod(a) > prod(b):
  prev_result = prod(a) + prod(b)
  b.append(a.pop(0))

  if prev_result < prod(a) + prod(b):
    a.append(b.pop(-1))
    break
  
print(prod(a)-1 +prod(b)-1)

Submission status: Runtime Error

Solution code:
import sympy

N = int(input())

a = sympy.factorint(N)
key = []
f = []
serch_mini = []

for i in a:
    key.append(i)

for i in key:
    b = a[i]
    for j in range(b):
        f.append(i)

for i in range(len(f)):
    b = f[0:i+1]
    c = f[i+1:]
    bb = 1
    cc = 1
    for j in range(len(b)):
        bb *= b[j]
    for k in range(len(c)):
        cc *= c[k]
    serch_mini.append(bb+cc)

print(min(serch_mini)-2)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
import sympy
import numpy as np


def solve(N: int):

    fct = sympy.factorint(N)

    fct_list = []
    for key, item in zip(fct.keys(), fct.values()):
        fct_list += [key] * item

    result = 1e12

    if len(fct_list) == 2:
        x = fct_list[0]
        y = fct_list[1]
        print(x - 1 + y - 1)
    elif len(fct_list) == 1:
        x = fct_list[0]
        y = 1
        print(x - 1 + y - 1)

    else:
        for i in range(1, len(fct_list) - 1):

            x = np.prod(fct_list[: i + 1])
            y = np.prod(fct_list[i + 1 :])

            result = min(result, x - 1 + y - 1)
        print(result)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools
def p(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
n=int(input())
p=p(n)
if len(p)==1:
    print(p[0]-1)
    exit()
a=10**12
b=1
for i in p:
    b*=i
pp=int(len(p)**0.5) 
for k in range(pp,min(,len(p)pp+5)):    
    for i in itertools.combinations(p, k):
        c=np.prod(i)
        a=min(a,c+b//c)
print(a-2)

Submission status: Runtime Error

Solution code:
N=int(input())
c=0
rN=int(N**0.5)+1

for i in range(rN):
    xi = rN - i
    for j in range(N-xi) :
        yj= xi+j
        if ((xi)*(yj))==N:
            x=xi
            y=yj
            c=1
            break
    if c==1:break


d=x+y-2

print(d)

Submission status: Runtime Error

Solution code:
import collections


def num_check(N):
    for i in reversed(range(2, 100)):
        q, mod = divmod(N, i)
        if mod == 0:
            return i, q

    return 1, N


def num_check1(num):
    ans = []
    for i in range(1, num):
        if num % i == 0:
            ans.append(i)
    return ans


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


if __name__ == "__main__":
    N = int(input())
    c = collections.Counter(prime_factorize(N))
    num = c.most_common()
    if num[0][1] >= 2:
        ans = num[-1][0] * num[-2][0]
        ans = ans + int(N / ans)
    else:
        ans = num[-1][0] + int(N / num[-1][0])
    print(ans - 2)

Submission status: Runtime Error

Solution code:
N = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    a.sort()
    return a

def eval_ab(a, b):
    if a == 1 or b == 1:
        return a + b - 1
    else:
        return a + b - 2
    
def split(ary, a, b, i):
    e = eval_ab(a, b)

    if len(ary) == i:
        return eval_ab(a, b)
    v = ary[i]

    v1 = split(ary, a * v, b, i+1)
    v2 = split(ary, a, b * v, i+1)
    return min(v1, v2)

def light(ary):
    a = 1
    b = 1
    for v in ary:
        if a < b:
            a *= v
        else:
            b *= v
    return eval_ab(a, b)

ary = prime_factorize(N)
print(ary)

if len(ary) == 1:
    print(str(ary[0] - 1))
elif len(ary) == 2:
    cost = ary[0] + ary[1] - 2
    print(str(cost))
else:
    if N < 100000:
        v1 = split(ary, 1, 1, 0)
        print(v1)
    else:
        v1 = light(ary, 1, 1, 0)
        print(v2)
    #v2 = light(ary)
    #v1 = split(ary, 1, 1, 0)
    #print(v1, v2)
    #print(str(v))

Submission status: Runtime Error

Solution code:
import math

def make_divisors(n):
    divisors = []
    for i in range(int(math.sqrt(n))+1, 0, -1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
        if len(divisors) == 2:
            break
        
    return divisors

def main():
    target = int(input())

    a, b = make_divisors(target)
    a -= 1
    b -= 1
    print(a+b)
        
        
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N=int(input())
s=[]
k=[]
if N<10**4:
    for i in range(1,N):
        for j in range(1,N):
            if i*j==N:
                b=[i,j]
                s.append(b)
elif N>=10**4 and N<10**8:
    for i in range(10**4,N):
        for j in range(10**4,N):
            if i*j==N:
                b=[i,j]
                s.append(b)
elif N>=10**8 and N<10**12:
    for i in range(10**8,N):
        for j in range(10**8,N):
            if i*j==N:
                b=[i,j]
                s.append(b)
for g in s:
    k.append(abs((g[0])-g[1]))
Ncordinate=s[k.index(min(k))]
number=Ncordinate[0]-1+Ncordinate[1]-1
print(number)

Submission status: Runtime Error

Solution code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

min_value = 1000000000000
data = int(input())
ng_flag = False
divisors_array = make_divisors(data)
for i in range(0, len(divisors_array)):
    if(i % 2 == 0):
        if divisors_array[i] + divisors_array[i+1] < min_value:
            if i == 1:
                min_value = divisors_array[i] + divisors_array[i+1] - 1
            else:
                min_value = divisors_array[i] + divisors_array[i+1] - 2
print(min_value)

Submission status: Runtime Error

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N = int(input())
n = N
divs = []
a = 1
b = N


def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


Ps = primes(10 ** 6)
Ps.reverse()

for P in Ps:
    x, y = divmod(n, P)
    while y == 0:
        n = x
        divs.append(P)
        x, y = divmod(n, P)
if divs == [] or len(divs) == 1:
    print(N - 1)
    exit()
else:
    length = len(divs)
    for i in range(2 ** length):
        a1 = 1
        s = format(i, '025b')
        for j in range(length):
            #print("s[-j-1]:" + s[-j - 1])
            #print("divs[j]:" + str(divs[j]))
            if s[-j - 1] == '1':
                a1 = a1 * divs[j]
                #print("divs[j]" + str(divs[j]))
                #print("a1:" + str(a1))
        b1 = N // a1
        #print("a1:" + str(a1))
        if a1 + b1 < a + b:
            a = a1
            b = b1
# print(divs)
#print("str:" + s)
print(a+b-2)

Submission status: Runtime Error

Solution code:
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

n = int(input())
l = make_divisors(n)

ans = 999999999999999999
for i in range(0, len(l), 2):
  a = l[i]
  b = l[i+1]
  ans = min(ans,(a+b-2))
  
print(ans)

Submission status: Runtime Error

Solution code:
import math
N=int(input())
a=math.floor(math.sqrt(N))
for i in range(a,N+1):
  if N%i==0:
	print(int(i+N/i-2))
  	break

Submission status: Runtime Error

Solution code:
n = int(input())
hn = int(round(n/2))
a = n
l = [None,None]
for i in reversed(range(hn + 1)):
  if i != 0:
     if n/i == 0:
        if i + n/i < a:
          a = i + n/i
          l[0] = i
          l[1] = n/i
if 1 in l:
  ans = l[0] + l[1] -1
else:
  ans = l[0] + l[1] -2
print(ans)

Submission status: Runtime Error

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N = int(input())
n = N
divs = []
a = 1
b = N


def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


Ps = primes(10 ** 6)
Ps.reverse()

for P in Ps:
    x, y = divmod(n, P)
    while y == 0:
        n = x
        divs.append(P)
        x, y = divmod(n, P)
if divs == [] or len(divs) == 1:
    print(N - 1)
    exit()
else:
    length = len(divs)
    for i in range(2 ** length):
        a1 = 1
        s = format(i, '030b')
        for j in range(length):
            #print("s[-j-1]:" + s[-j - 1])
            #print("divs[j]:" + str(divs[j]))
            if s[-j - 1] == '1':
                a1 = a1 * divs[j]
                #print("divs[j]" + str(divs[j]))
                #print("a1:" + str(a1))
        b1 = N // a1
        #print("a1:" + str(a1))
        if a1 + b1 < a + b:
            a = a1
            b = b1
# print(divs)
#print("str:" + s)
print(a+b-2)

Submission status: Runtime Error

Solution code:
N=int(input())
c=0
INF=2000000
x=[]
y=[]

rN=int(N**0.5)

for i in range(rN):
    if (i>1)&(i%2==1) : continue
    xi = rN - i
    for j in range(rN-i) :
        yj= rN - j
        if ((xi)*(yj))==N:
            x=xi
            y=yj
            C=1
            break
    if c==1:break


d=x+y-2
print(d)

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
m=np.floor(np.sqrt(n))

l=[]
for i in range(1,m+1,1):
    if n%i==0:
        a=i+(n/i)
        l.append(a)
        
c=int(min(l))
print(c-2)

Submission status: Runtime Error

Solution code:
N=int(input())
s=[]
k=[]
from math import*
if N<10**4
    for i in range(1,N):
        for j in range(1,N):
            if i*j==N:
                b=[i,j]
                s.append(b)
elif N>=10**4 and N<10**8:
    for i in range(10**4,N):
        for j in range(10**4,N):
            if i*j==N:
                b=[i,j]
                s.append(b)
elif N>=10**8 and N<10**12:
    for i in range(10**8,N):
        for j in range(10**8,N):
            if i*j==N:
                b=[i,j]
                s.append(b)
for g in s:
    k.append(abs((g[0])-g[1]))
Ncordinate=s[k.index(min(k))]
number=Ncordinate[0]-1+Ncordinate[1]-1
print(number)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
sum = N - 1
b = int(math.sqrt(N))
for i in range(2, b+1):
    if(N%i==0):
        if((a/i+i-2)<=sum):
            sum = N/i+i-2

print(sum)

Submission status: Runtime Error

Solution code:
import math
import itertools

N = int(input())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+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

factrist = factorization(N)

tmplist = []

# print(factrist)

a = 1
b = 1

for i in factrist:
        tmp = i[1]
        num = i[0]
        while tmp >= 2:
                a = a * num
                b = b * num
                tmp = tmp - 2
        if tmp == 1:
                tmplist.append(i[0])

sq_N = math.sqrt(N)

# print(a)
# print(b)
# print(tmplist)

sigma = 1
for i in tmplist:
        sigma *= i

L = len(tmplist)
if(L > 2):
        h_L = int(L / 2)

        ans_list = []

        List = itertools.permutations(tmplist, h_L)
        for i in List:
                ans = 1;
                for j in i:
                        ans *= j;
                ans_list.append(ans)



        sq_sigma = math.sqrt(sigma)
        ans_list.sort()

        boader = 0
        for i in range(len(ans_list)):
                if(ans_list[i] > sq_sigma):
                        boader = i
                        break

        # print(boader)
        # print(ans_list)
        # print(ans_list[boader])
        # print(ans_list[boader-1])

        print(a * ans_list[boader] + b * ans_list[boader-1] - 2)

else:
        if(L == 0):
                print(a + b -2)
        if(L == 1):
                print(a * tmplist[0] + b - 2)
        if(L == 2):
                print(a * tmplist[0] + b * tmplist[1] - 2)
altair@capella:~/Project/comp_lab/kyougi/abc136$

Submission status: Runtime Error

Solution code:
import math
ans = math.inf
n = int(input())
a = list(range(1,math.ceil(math.sqrt(n))+1))
for i in a:
    s = n/i
    if s==int(s):
        ans = min(i+s-2,ans)
print(int(ans))

Submission status: Runtime Error

Solution code:
N=int(input())
s=[]
k=[]
from math import*
if N<10**4
    for i in range(1,N):
        for j in range(1,N):
            if i*j==N:
                b=[i,j]
                s.append(b)
elif N>=10**4 and N<10**8:
    for i in range(10**4,N):
        for j in range(10**4,N):
            if i*j==N:
                b=[i,j]
                s.append(b)
elif N>=10**8 and N<10**12:
    for i in range(a,N):
        for j in range(a,N):
            if i*j==N:
                b=[i,j]
                s.append(b)
for g in s:
    k.append(abs((g[0])-g[1]))
Ncordinate=s[k.index(min(k))]
number=Ncordinate[0]-1+Ncordinate[1]-1
print(number)

Submission status: Runtime Error

Solution code:
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
 
    divisors.sort()
    return divisors
  
N = int(input())
Nlist = make_divisions(N)
L = len(Nlist)
if L%2==0:
    print(Nlist[int(L/2)]+Nlist[int(L/2)-1]-2)
else:
    print(int(math.sqrt(N)*2-2)

Submission status: Runtime Error

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N = int(input())
n = N
divs = []
a = 1
b = N


def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


Ps = primes(10 ** 6)
Ps.reverse()

for P in Ps:
    x, y = divmod(n, P)
    while y == 0:
        n = x
        divs.append(P)
        x, y = divmod(n, P)
if divs == [] or len(divs) == 1:
    print(N - 1)
    exit()
else:
    length = len(divs)
    for i in range(2 ** length):
        a1 = 1
        s = format(i, '020b')
        for j in range(length):
            #print("s[-j-1]:" + s[-j - 1])
            #print("divs[j]:" + str(divs[j]))
            if s[-j - 1] == '1':
                a1 = a1 * divs[j]
                #print("divs[j]" + str(divs[j]))
                #print("a1:" + str(a1))
        b1 = N // a1
        #print("a1:" + str(a1))
        if a1 + b1 < a + b:
            a = a1
            b = b1
# print(divs)
#print("str:" + s)
print(a+b-2)

Submission status: Runtime Error

Solution code:
from collections import deque
import math
ans = 0
n = int(input())
h = math.ceil(n/2)
board = [[0]*h for _ in range(h)]
for i in range(1,h + 1):
  for j in range(1,h + 1):
    board[i - 1][j - 1] = i * j
sx = 1
sy = 1
dist = [[-1]*h for _ in range(h)]
que = deque([(sy - 1,sx - 1)])
dist[sy - 1][sx - 1] = 0
while que:
  y,x = que.popleft()
  if board[y][x] == n:
    ans = dist[y][x]
    break
  for y1,x1 in [(y + 1,x),(y, x + 1)]:
    if y1 < 0 or x1 < 0 or y1 >= h or x1 >= h:
      continue
    if dist[y1][x1] != -1:
      continue
    dist[y1][x1] = dist[y][x] + 1
    que.append((y1,x1))
print(ans)

Submission status: Runtime Error

Solution code:
def make_divisors(n):
    divisors = []
    for i in range(int(n**0.5)+1, 0, -1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
        if len(divisors) == 2:
            break
        
    return divisors

def main():
    target = int(input())

    a, b = make_divisors(target)
    a -= 1
    b -= 1
    print(a+b)
        
        
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
  
N = int(input())
Nlist = make_divisions(N)
L = len(Nlist)
if L%2==0:
    print(Nlist[int(L/2)]+Nlist[int(L/2)-1]-2)
else:
    print(int(math.sqrt(N)*2-2)

Submission status: Runtime Error

Solution code:
import math
n= int(input())
max=n

for i in range(1,int(math.sqrt(n))):
    if(n%i==0):
        if(max > abs(n/i-i)):
            max= abs(n/i-i)
            tmp = n/i+i-2
        else:
            break
print(int(tmp))

Submission status: Runtime Error

Solution code:
n = int(input())
min = n+1
kaisu = int(n-1)
if 
for i in range(kaisu):
    if n%(i+1)==0:
        tmp = i+(n/(i+1))-1
        if min > tmp:
            min = tmp
    if (i+1)**2>n:
        break

print(int(min))

Submission status: Runtime Error

Solution code:
dN = int(input())
yaku = 1

import math

    



if N % 2 == 0:
	yaku = 2
	
for i in range(3,int(math.sqrt(N))+1 ,1):
	if N % i == 0:
		yaku = i
		
		
yaku2 = int(N/yaku)

print(int(yaku2+yaku - 2))

Submission status: Runtime Error

Solution code:
n = int(input())

flag == False
check = []

for i in range(n - 1, 1, -1):
    if (n % i == 0):    
        flag == True
        a = i
        b = n / i
        check.append(a + b - 2)

if flag == True:    
    check.sort()
    print(int(check[0]))
else:
    print(n - 1)

Submission status: Runtime Error

Solution code:
N = int(input())
if N%2==1:
  print(N-1)
else:
  ans = []
  for i in range(1,N):
    for j in range(1,N):
      cnt=0
      if i*j==N:
        cnt +=i-1
        cnt +=j-1
        ans.append(str(cnt))
  ans=min(ans)
  print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
si = []
sj = []
if n%2!=0 and n%3!=0:
    print(n-1)
else:
    for i in range(2,(n//2)+1):
        if n%i==0:
            if i in sj:
                continue
            else:
                si.append(i)
                sj.append(n//i)

    s1 = max(si)
    s2 = n//s1
    print(s1+s2-2)