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:
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 == []:
    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:
n = int(input())
s = int(math.sqrt(n))
a = 0
for i in range(s, 0, -1):
    if n % i == 0:
        a = i
        break
if a == 0:
    print(n - 1)
else:
    print(int((a - 1) + (n / a - 1)))

Submission status: Runtime Error

Solution code:
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 = 1
B = 1
for i in a:
  if(A > B):
    B *= i
  elif(B > A):
    A *= i
  else:
    A *= i
print(A + B - 2)

Submission status: Runtime Error

Solution code:
#-*- coding:utf-8 -*-
n = int(input())
for x in range(1,n/2+1):
    for y in range(1,n/2+1):
        if n == x*y:
            print(x+y-2)
            quit()

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long int n,z;
    cin>>n;
    if ((int(2*(n**0.5)))<(2*(n**0.5)))
    {
    z=((int(2*(n**0.5)))+1)
    }
    else
    {
        z=(int(2*(n**0.5)))
    }
    
    cout<<(z-2);
    return 0;
}

Submission status: Runtime Error

Solution code:
n = int(input())

for x in range(1, 10**6+1):
    if x**2 >= n:
        y = x
        break

i, j = y, y
for x in range(10**5):
    if i*j == n:
        ans = i + j - 2
        break
    elif i*j > n:
        i -= 1
    elif i*j < n:
        j += 1

print(ans)

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= n/i-i
            tmp = n/i+i-2
        else:
            break
print(int(tmp))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
k = n+1
a = np.array(range(k))
b = np.reshape(a, (k,1))
c = a*b
pos = np.where(c==n)
print((pos[0]+pos[1]).min()-2)

Submission status: Runtime Error

Solution code:
n = int(input())

a = []
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)

Submission status: Runtime Error

Solution code:
#%%
n = int(input())

x = int(n**0.5)
x += 1
for i in range(x, 1, -1):
    if n%i == 0:
        a = i
        b = n//i
        break
#print(a, b)

print(a+b-2)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

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():
    n = int(input())

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

Submission status: Runtime Error

Solution code:
N=int(input())
num=[]
num_num=0
list_a=[]
list_b=[]

for i in range(1,int(N/2+1)):
    if N%i==0:
        num_num+=1
        num.append(i)

if num_num%2==0:
    for i in range(0,int(num_num/2)):
        list_a.append(num[i])
    for i in range(int(num_num/2),num_num):
        list_b.append(num[i])
else :
    for i in range(0,int(num_num/2)+1):
        list_a.append(num[i])
    for i in range(int(num_num/2)+1,num_num):
        list_b.append(num[i])
    
print(max(list_a)-1+min(list_b)-1)

Submission status: Runtime Error

Solution code:
from math import sprt

n=int(input())
for i in range(int(sqrt(n)),2,-1):
  if n%i==0:
    print(i-1 + int(n/i)-1)
    break
else:
  print(n-1)

Submission status: Runtime Error

Solution code:
n = int(input())
ans = 1 + n
if n % 2 == 0:
    max = n / 2 + 1
else:
    max = (n + 1) / 2

for i in range (1, max):
    if max % i == 0 and i + max / i < ans:
        ans = i + max /i

print(int(ans - 2))

Submission status: Runtime Error

Solution code:
def get_min_move(n):#素因数分解する
    a = []#素因数リスト
    one_flg = 0
    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(reverse=True)
    if len(a) == 1:
        print(a[0]-1)
        return
    if(a[0] == 1):
        one_flg = 1
    while len(a) != 2:
        min1 = a.pop()
        min2 = a.pop()
        a.append(min1*min2)
    if one_flg = 1:
        print(a[0] + a[1] -1)
    else:
        print(a[0] + a[1] -2)
    return

num = int(input())
get_min_move(num)

Submission status: Runtime Error

Solution code:
n = int(input())
ans = 1 + n
if n % 2 == 0:
    max = n / 2 + 1
else:
    max = (n + 1) / 2

for i in range (1, max):
    if n % i == 0 and i + n / i < ans:
        ans = i + n /i

print(int(ans - 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:
n = int(input())
m = int(n / 2)

divs = []

for i in range(m):
  if i == 0:
    continue
  mod = n % i
  if mod == 0:
    an = int(n/i)
    if i <= an:
      divs.append(i)
      divs.append(an)
    else:
      break

max = len(divs) -1
print(divs[max] + divs[max-1] - 2)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())
s=[]
k=[]
for i in range(1,N):
    for j in range(1,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())
m=math.sqrt(n)
m=math.floor(m)
li=[]
for i in range(1,m):
    a=i+n/i
    li.append(a)
li=[li[i] for i in range(m-1) if li[i].is_integer()]
print(int(min(li))-2)

Submission status: Runtime Error

Solution code:
n = int(input())
mi = 1000
mi1 = 0
mi2 = 0
for i in range(1,n/2+1):
	q = n // i
	mod = n % i
	if mod == 0:
		if mi > abs(q - i):
			mi = abs(q-1)
			mi1 = i
			mi2 = q
print(mi1+mi2-2)

Submission status: Runtime Error

Solution code:
from math import sprt

n=int(input())
for i in range(int(sqrt(n)),2,-1):
  if n%i==0:
    print(i-1 + n//i-1)
    break
else:
  print(n-1)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
a = np.array(range(n))
b = np.reshape(a, (n,1))
c = a*b
pos = np.where(c==n)
print((pos[0]+pos[1]).min()-2)

Submission status: Runtime Error

Solution code:
n = int(input())

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)


if len(divisors) > 2:
    print(min(divisors[-1]+divisors[-2]-2,divisors[-3]+divisors[-4]-2))
else:
    print(divisors[-1]+divisors[-2]-2)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def get_min_move(n):#素因数分解する
    a = []#素因数リスト
    one_flg = 0
    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(reverse=True)
    print(a)
    if len(a) == 1:
        print(a[0]-1)
        return
    if(a[0] == 1):
        one_flg = 1
    while len(a) != 2:
        min1 = a.pop()
        min2 = a.pop()
        a.append(min1*min2)
    if one_flg = 1:
        print(a[0] + a[1] -1)
    else:
        print(a[0] + a[1] -2)
    return

num = int(input())
get_min_move(num)

Submission status: Runtime Error

Solution code:
import math
A = int(input())
p = int(math.sqrt(A))
all_lis = []
ans_lis = []

for i in range(1,p,1):
    if A % i == 0:
        kumi = [i,int(A/i)]
        all_lis.append(kumi)

for j in all_lis:
    ans_lis.append(j[0]+j[1])
    
print(int(min(ans_lis)-2))

Submission status: Runtime Error

Solution code:
n = int(input())
ans = []
aim = []
if n%2!=0 and n%3!=0:
    print(n-1)
else:
    for i in range(3,n//2+1):
         if n%i==0:
                ans.append([i,n//i])
    for j in range(len(ans)):
        k = sum(ans[j])
        aim.append(k)
    print(min(aim)-2)

Submission status: Runtime Error

Solution code:
N = int(input())
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())
for i in reversed(range(int(N**0.5))):
    if N % i == 0:
        a=i
        break
print(int(a+int(N/a)-2))

Submission status: Runtime Error

Solution code:
import math
A = int(input())
p = int(math.sqrt(A))
all_lis = []
ans_lis = []

for i in range(1,p,1):
    if A % i == 0:
        kumi = [i,int(A/i)]
        all_lis.append(kumi)
        
print(all_lis)

for j in all_lis:
    ans_lis.append(j[0]+j[1])
    
print(int(min(ans_lis)-2))

Submission status: Runtime Error

Solution code:
import math

    
def main():
    Input = [input() for i in range(1)]
    N = int(Input[0])
    x = math.sqrt(N)
    if x.is_integer():
        print(int(x+N/x-2))
    else:
        while x >= 1:
            x = math.floor(x)-1
            y = N/x
            if y.is_integer():
                print(int(x+y-2))
                break

        
        
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import itertools
import operator
import functools
target_list = factorize(int(input()))
loop=len(target_list)+1
ans=1000000000000

def 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

for i in range(loop):
    a=target_list[:i]
    b=target_list[i:]
    if len(a)>0:
        a=functools.reduce(lambda x,y:x*y,target_list[:i])
    else:
        a=1
    if len(b)>0:    
        b=functools.reduce(lambda x,y:x*y,target_list[i:])
    else:
        b=1
    ans=min(ans,a+b-2)

print(ans)

Submission status: Runtime Error

Solution code:
import math
a,b,x =map(int,input().split( ))
if x >= (a**2*b/2):
    k=2*x/(a**2)-b
    cos=math.sqrt((b-k)**2/((a**2)+(b-k)**2))
    print(90-math.degrees(math.acos(cos)))
else:
    k=2*x/(a*b)
    cos=math.sqrt(b**2/(b**2+k**2))
    print(90-math.degrees(math.acos(cos)))

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
a = np.array(range(n))
b = np.reshape(a, (k,1))
c = a*b
pos = np.where(c==n)
print((pos[0]+pos[1].min()-2))

Submission status: Runtime Error

Solution code:
import math

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

def main1():
    Input = [input() for i in range(1)]
    N = int(Input[0])
    fact = factorization(N)
    ff = []
    for fn in fact:
        for i in range(fn[1]):
            ff.append(fn[0])
    ans = 10000000000000
    fN = len(ff)
    for wake in range(2**(fN-1)):
        wake2 = format(wake, '0'+str(fN-1)+'b')
        A = ff[-1]
        for i in range(fN-1):
            if wake2[i] == '1':
                 A = A*ff[i]   
        B = N / A
        if A + B - 2 < ans:
            ans = int(A+B-2)
    print(ans)
    
def main1():
    Input = [input() for i in range(1)]
    N = int(Input[0])
    x = math.sqrt(N)
    if x.is_integer():
        print(int(x+N/x-2))
    else:
        while x >= 1:
            x = math.floor(x)-1
            y = N/x
            if y.is_integer():
                print(int(x+y-2))
                break

        
        
if __name__ == "__main__":
    main1()

Submission status: Runtime Error

Solution code:
def get_min_move(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(reverse=True)
    if a[-1] == 1:
        print(a[0]-1)
        return
    while len(a) != 2:
        min1 = a.pop()
        min2 = a.pop()
        a.append(min1*min2)
    print(a[0] + a[1] -2)
    return

num = int(input())
get_min_move(num)

Submission status: Runtime Error

Solution code:
import math

N = int(input())

k = int(math.sqrt(N))

for i in range(1,k)[-1]:
  if N%i==0:
      print(int(N%i)+i)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
r = np.arange(1, n+1)
mask = n%r== 0
ans = r[mask] + (n/r[mask]) -2
print(int(np.min(ans)))

Submission status: Runtime Error

Solution code:
n = int(input())

for x in range(1, 10**6):
    if x**2 >= n:
        y = x
        break

i, j = y, y
for x in range(10**6):
    if i*j == n:
        ans = i + j - 2
        break
    elif i*j > n:
        i -= 1
    elif i*j < n:
        j += 1

print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
for i in reversed(range(int(N**0.5))):
    if N % i == 0:
        a=i
        break
print(int(a+(N/a)-2))

Submission status: Runtime Error

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

yakusu = make_divisors(n)

k = (len(yakusu)-1)//2
a = yakusu[k] + yakusu[k+1] -2

if len(yakusu) <= 2:
    print(a)
else:
    b = yakusu[k-1] + yakusu[k+2] - 2
    if a > b :
        print(b)
    else:
        print(a)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
k = int(np.sqrt(n))
a = np.array(range(k))
b = np.reshape(a, (k,1))
c = a*b
pos = np.where(c==n)
print((pos[0][i]+pos[1][i].min()-2)

Submission status: Runtime Error

Solution code:
import math

n = int(input())

sqrt_n = int(math.sqrt(n))

for i in reversed(range(sqrt_n)):
  if(n%i == 0):
    print(i + n%i -2)

Submission status: Runtime Error

Solution code:
import math
A = int(input())
p = int(math.sqrt(A))
all_lis = []
ans_lis = []

for i in range(1,p,1):
    if A % i == 0:
        kumi = [i,A/i]
        all_lis.append(kumi)

for j in all_lis:
    ans_lis.append(j[0]+j[1])
    
print(int(min(ans_lis)-2))

Submission status: Runtime Error

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Factoring by trial split
def getPrimeList(n):
  l=[]
  t=int(math.sqrt(n))+1
  
  for a in range(2,t):
    while n%a==0:
      n//=a
      l.append(a)
  
  if n!=1:
    l.append(n)
  
  return l

def main():
  n=I()
  a=getPrimeList(n)

  ans=inf
  b=len(a)
  for i in range(2**b//2):
    _a=_b=1
    for j,x in enumerate(b):
      if ((i>>j)&1):
        _a*=x
      else:
        _b*=x
    ans=min(ans,_a+_b-2)
  return ans

# main()
print(main())

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
k = int(np.sqrt(n))
a = np.array(range(k))
b = np.reshape(a, (k,1))
c = a*b
pos = np.where(c==n)
print((pos[0][i]+pos[1][i].min())

Submission status: Runtime Error

Solution code:
import math

n=int(input())
m=int(math.sqrt(n))
for i in reverse(range(1,m+1)):
	if n%i==0:
		print(int(i+n/i-2))
		break

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sympy as sp
import heapq as hq
N = int(input())
A = sp.factorint(N)
B = []
hq.heapify(B)
for i,j in A.items():
    while j != 0:
        hq.heappush(B,i)
        j -= 1
leng = len(B)
if leng == 1:
    print(B[0]-1)
    exit()

while leng > 2:
    a = hq.heappop(B)
    b = hq.heappop(B)
    hq.heappush(B,a*b)
    leng -= 1
print(sum(B)-2)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
i = 1
min = 1000000000000
for _ in range(N):
  if N % i == 0:
    j = N/i
    sum = j + i
    if sum < min:
      min = sum
      ans = i-1+j-1
    else:
      break
  i += 1
print(ans)

Submission status: Runtime Error

Solution code:
from sympy import isprime
import math
n=int(input())
if (isprime(n))==True:
    print(int(n-1))
else:
    N=int(math.sqrt(n))
    for i in reversed(range(N)):
        if n%(i+1)==0:
            print(int((n/(i+1))+i-1))
            break

Submission status: Runtime Error

Solution code:
import sys

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())

sys.setrecursionlimit(10 ** 9)
INF = float('inf')


def main():
    N = INT()

    num = [i + 1 for i in range(ceil(sqrt(N)))]

    minimum = INF
    for i in num:
        if N % i == 0:
            temp = i + N//i
            if temp < minimum:
                minimum = temp

    print(minimum - 2)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def factors(n):    
    return set(reduce(list.__add__, 
                ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

def prime(n1):
	for i in range(2, int(math.sqrt(n1))+1):
		if n1%i == 0:
			return False
	return True

n = int(input())
if prime(n):
	print(n - 1)
else:
	k = sorted(list(factors(n)))
	#print(k)
	if len(k) %2 != 0:
		if k[len(k)//2]*k[len(k)//2] == n:
			print(2*k[len(k)//2] - 2)
		#else:

	else:
		s = k[len(k)//2 - 1] + k[len(k)//2]
		print(s - 2)

Submission status: Runtime Error

Solution code:
x = int(input())
cand_list = []

for i in range(1, int(x**(1/2))):
    if x%i==0:
      cand_list.append([i, x//i])
        
print(min([sum(cand_i)-2 for cand_i in cand_list]))

Submission status: Runtime Error

Solution code:
n = int(input())
num = 1
for i in range(1, int(np.sqrt(n))):
    if n % i == 0:
        num = i
ans = int(num -1 + (n / num) -1)
print(ans)

Submission status: Runtime Error

Solution code:
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
def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr

    # データの状態に左右されないためにrandom.choice()を用いることもある。      
    # ref = random.choice(arr)                                                 
    ref = arr[0]
    ref_count = 0

    for ele in arr:
        if ele < ref:
            left.append(ele)
        elif ele > ref:
            right.append(ele)
        else:
            ref_count += 1
    left = quick_sort(left)
    right = quick_sort(right)
    return left + [ref] * ref_count + right

a = quick_sort(make_divisors(n))

if len(a)//2==0:
    x = len(a)//2-1
else:
    x = len(a)//2
xx = a[x]
yy= n//xx

print(xx-1+yy-1)

Submission status: Runtime Error

Solution code:
# C
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
ans = N - 1
lst = make_divisors(N)
for i in range(0, len(lst), 2):
    num = lst[i] + lst[i+1] - 2
    ans = min(ans,num)

print(ans)

Submission status: Runtime Error

Solution code:
abc = input()
abc_int = int(abc)
prolist = []
chk = int(abc_int**0.5)
print(chk)
for c1 in range(chk):
    for c2 in range(chk):
        if (c1+1)*(c2+1) == abc_int:
            prolist.append(c1+c2)
print(min(prolist))

Submission status: Runtime Error

Solution code:
ls = []

n = int(input())

if n % 2 != 0:
    print(n-1)
else:
    for i in range(1,round(n/2)):
        if n % i == 0:
            ls.append(i)
        
        
    length = len(ls)
    ans = ls[length-1]
    ans2 = (round(n/ans))
    print(ans+ans2-2)

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())

n = []
n = make_divisors(N)

cnt = 999999999999999
if len(n) >= 2:
    for i in range(0,len(n),2):
        t = int(n[i])-1 + int(n[i+1])-1
        if cnt > t:
            cnt = t
print(cnt)

Submission status: Runtime Error

Solution code:
def factors(n):    
    return set(reduce(list.__add__, 
                ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

def prime(n1):
	for i in range(2, n1//2):
		if n1%i == 0:
			return False
	return True

n = int(input())
if prime(n):
	print(n - 1)
else:
	k = sorted(list(factors(n)))
	#print(k)
	s = k[len(k)//2 - 1] + k[len(k)//2]
	print(s - 2)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
N_sqrt = int(math.sqrt(N))

for i in range(1,N_sqrt):
    if N % i == 0:
        x = i
        y = int(N/i)

print(x+y-2)

Submission status: Runtime Error

Solution code:
target = int(input())
possibleAns = []
 
for i in range(1,10):
  for j in range(1,10):
    if i*j == target:
		possibleAns.append(i+j)
print(min(possibleAns))

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())

n = []
n = make_divisors(N)

cnt = 999999999999999
for i in range(0,len(n),2):
    t = int(n[i])-1 + int(n[i+1])-1
    if cnt > t:
        cnt = t
print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())

lst = []
flag = False

for a in range(1, (N+1)//2):
    if N % a == 0:
        b = N / a       
        lst.append((a-1)+(b-1))
                
print(int(min(lst)))

Submission status: Runtime Error

Solution code:
target = int(input())
possibleAns = []

for i in range(1,10):
  for j in range(1,10):
    if i*j == taget:
		possibleAns.append(i+j)
print(min(possibleAns))

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())
i, j = 1, 1
l = make_divisors(N)
len_l = len(l)
if len_l % 2 == 1:
    idx = (len_l-1)/2
    print((l[idx]-i) + (l[idx]-j))
else:
    idx = int(len_l / 2)
    print(sum(l[idx-1:idx+1])-2)

Submission status: Runtime Error

Solution code:
n=int(input())
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
p=make_divisors(n)

l=len(p)
if l%2==1:
  ans=p[l-1]*2-2
  
else:
  ans=p[l-1]+p[l-2]-2
  
print(ans)

Submission status: Runtime Error

Solution code:
import math
n = input()
n = int(n)
spl_list = [1]
for i in range(1,round(math.sqrt(n)) + 1):
  if n % i == 0:
    spl_list.append(i)

max_i = max(spl_list)
max_j = n / max_i
print(round(max_i + maxj -2))

Submission status: Runtime Error

Solution code:
import sys
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
def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr

    # データの状態に左右されないためにrandom.choice()を用いることもある。      
    # ref = random.choice(arr)                                                 
    ref = arr[0]
    ref_count = 0

    for ele in arr:
        if ele < ref:
            left.append(ele)
        elif ele > ref:
            right.append(ele)
        else:
            ref_count += 1
    left = quick_sort(left)
    right = quick_sort(right)
    return left + [ref] * ref_count + right

a = quick_sort(make_divisors(n))
x = len(a)//2-1
y = x+1
xx = a[x]
yy= a[y]
print(xx-1+yy-1)

Submission status: Runtime Error

Solution code:
N = int(input())

ans_lis = []
for i in range(1,10**6):
    if N%i==0:
        ans_lis.appe
        nd(i+(N//i))
print(min(ans_lis)-2)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
ans=[]

nr=int(n**0.5)


for i in range(1,nr):
    if n%i==0:
        ans.append(i+n//i)
   
ans2=sorted(ans)
print(ans2[0]-2)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
p = int(math.sqrt(N))

def search(N, p):
#     print(p, N % p)
    if N % p == 0:
        q = int(N / p)
        return p, q
    else:
        if p * N // p > N:
            p, q = search(N, p - 1)
        else:
            p, q = search(N, p + 1)
    
    return p, q

p, q  = search(N, p)
print(p + q - 2)

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())

n = make_divisors(N)

cnt = 999999999999999
for i in range(0,len(n),2):
    t = n[i]-1 + n[i+1]-1
    if cnt > t:
        cnt = t
print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def prime(j):
    for k in range(2, int(j**0.5)):
        if j % k == 0: return False
    return True

n = int(input())
ans = 0
if prime(n): print(n-1)
for i in range(int(n/2))[::-1]:
    if n % i == 0:
        ans = i
        break
print(int((ans-1) + (n/ans-1)))

Submission status: Runtime Error

Solution code:
from math import sqrt 

n=int(input())
count=[]

for i in range(1,int(sqrt(n))):
    if n%i==0:
        count.append(i+n/i)

print(int(min(count)-2))

Submission status: Runtime Error

Solution code:
for i in range(int(N**0.5), 0, -1):
    if N % i == 0:
        x = i
        y = N // i
        break
print(x+y-2)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
import sys

N = int(input())

for i in reversed(range(int(math.sqrt(N)))):
  if N % i == 0:
    print(i + N / i)
    sys.exit()

Submission status: Runtime Error

Solution code:
import math

n = int(input())

k = math.floor(math.sqrt(n))

for i in reversed(range(k)):
  if n/i == n//i:
    print(int(n/i + i -2))
    exit()