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.

Solution (Python):
n = int(input())
l = []
for i in range(1,1000001):
    a = n / i
    if a.is_integer():
        l.append(i+n/i)
print(int(min(l)-2))

Solution (Python):
import math
 
x = int(input())
 
ans = 100000000000
for i in range(1, int(math.sqrt(x)) + 1): 
    if x % i == 0:
        tmp = int((i - 1) + (x / i - 1))
        if ans > tmp:
            ans = tmp
 
print(tmp)

Solution (Python):
import math as m

n = int(input())

sn = int(m.sqrt(n))

while sn > 0:
    if n % sn == 0:
        print(sn+(n//sn)-2)
        break
    sn -= 1

Solution (Python):
import math

x = int(input())

tmp = []

for i in range(1, int(math.sqrt(x)) + 1):
    if x % i == 0:
        tmp.append(int((i - 1) + (x / i - 1)))

print(min(tmp))

Solution (Python):
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
res = float('inf')
for i in range(1,2*10**6):
    if (n/i).is_integer():
        res = min(res, i + n/i)
print(int(res-2))

Solution (Python):
import math
 
N = int(input())
ans = N
n = 1
while n <= math.sqrt(N):
    if N%n == 0:
        ans = min(ans, int(N/n + n -2))
    n += 1  

print(ans)

Solution (Python):
import math
N = int(input())
n = int(math.sqrt(N))
 
while n > 0:
    if N%n == 0:
        print(int(N/n + n - 2))
        break
    n -= 1

Solution (Python):
N=int(input())
n=N-1
for i in range(1,int(N**(1/2))+1):
    if N%i==0:
      n=min(n,i+N/i-2)
print(int(n))

Solution (Python):
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
 
n = sorted(make_divisors(N))

sum_yakusuu = N
for _n in n:
    if _n == 1:
        continue
    if _n+N/_n < sum_yakusuu:
        sum_yakusuu = int(_n+N/_n)
        bef_n = _n
    else:
        if len(n) == 2:
            print(int(_n-1))
        else:
            print(int(bef_n+N/bef_n-2))
        break

Solution (Python):
import math

N = int(input())


def main():
    root_n = math.sqrt(N)
    answer = -1
    for a in range(1, int(root_n) + 1):
        if N % a == 0:
            b = N // a
            v = a + b - 2
            if answer == -1 or answer > v:
                answer = v
    print(v)

main()

Solution (Python):
import math
import sys

n = int(input())

ans = sys.maxsize

for i in range(1, int(math.sqrt(n)) + 1):
    if n % i == 0:
        ans = min((i - 1) + (n // i - 1), ans)

print(ans)

Solution (Python):

import sys
import numpy as np


def solve(N: int):
    result_list = []
    for i in range(1, int(np.sqrt(N)) + 1):
        if N % i == 0:
            result_list.append(i - 1 + N // i - 1)
        else:
            pass
    print(min(result_list))
    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))  
    solve(N)


if __name__ == "__main__":
    main()

Solution (Python):
from math import sqrt

N = int(input())

n = int(sqrt(N))
ans = 10**9

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

Solution (Python):
from math import ceil, sqrt
N = int(input())
for i in range(ceil(sqrt(N)),0,-1):
    if N%i == 0:
        print(i + N//i -2)
        break

Solution (Python):
import math

def sq(n):
    for i in range(math.ceil(math.sqrt(N)), -1, -1):
        if n % i == 0:
            return (i, n//i)

N = int(input())
a, b = sq(N)
print(a + b - 2)

Solution (Python):


N = int(input())
num = N
for i in range(1, pow(10,6) + 1):
    if N / i == N // i:
        num = min(num, N // i + i - 2)
print(num)

Solution (Python):
import math

n = int(input())

l = []

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

print(min(l))

Solution (Python):
n=int(input())
 
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)
            return divisors
 
    
    return divisors
 
 
k = make_divisors(n)
if len(k) == 2:
    print(sum(k)-2)
else:
    print(k.pop()*2-2)

Solution (Python):
n = int(input())

ans=n+1
for i in range(2,10**6+1):
    if n%i==0:
        ans = min(ans, i+n//i)

print(ans-2)

Solution (Python):
import math

N = int(input())

A = int(math.sqrt(N))

for i in reversed(range(1, A + 1)):
    if N % i == 0:
        print(i + (N // i) - 2)
        exit()

Solution (Python):
n=int(input())
 
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)
            return divisors
 
    
    return divisors
 
 
k = make_divisors(n)
if len(k) == 2:
    print(sum(k)-2)
else:
    print(k.pop()*2-2)

Solution (Python):
N = int(input())

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

Solution (Python):
import math
n=int(input())

d=1e12
for i in range(1,int(math.sqrt(n))+1):
    if(n % i == 0):
        m=n/i + i- 2;
        if(m < d):
            d=m
print(int(d))

Solution (Python):
n = int(input())
x = n
import math
for i in range(int(math.sqrt(n))):
        if n%(i+1) == 0:
            if i+1 + n/(i+1) < x:
                x = i+1 + n/(i+1)
if x == n:
    print(x-1)
else:
    print(int(x-2))

Solution (Python):
import math
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
a=make_divisors(n)
if len(a)%2==1:
  print(2*int(math.sqrt(n))-2)
if len(a)%2==0:
  b=a[len(a)//2-1]
  c=a[len(a)//2]
  print(b+c-2)

Solution (Python):
import math
N = int(input())

for i in range(int(math.sqrt(N)), 0, -1):
    if N//i*i == N:
        print(N//i+i-2)
        break

Solution (Python):
import math
N = int(input())
tmp = math.ceil(N**(1/2))
ans = N
for i in range(1,tmp+1):
    if N%i == 0:
        A = max(N//i-1,0)
        B = max(i-1,0)
        ans = min(ans,A+B)

print(ans)

Solution (Python):
import numpy as np

n = int(input())

patterns = []

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

print(min(patterns))

Solution (Python):
import math
N = int(input())

sosu_dict = {}
a = N
b = N

for i in range(1, int(math.sqrt(N))+1):
    if a % i == 0:
        sosu_dict[i] = int(a/i)
        b = a/i
 

if b > 1:
    sosu_dict[int(b)] = int(a/b)



sum = 10 ** 15 +1
for key in sosu_dict:
    if (key + sosu_dict[key]) < sum:
        sum = key + sosu_dict[key]

print(sum-2)

Solution (Python):
N = int(input())
m = int((N**0.5 )//1  + 1)


res = 1000000000000
for i in range(1, m):
    if N%i == 0:
        o =  int(N/i)
        if res > o + i:
            res = o + i
print(res-2)

Solution (Python):
import math


def main():
    n = int(input())
    a = 1
    b = n
    
    ans = n - 1 
    
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            a = int(i)
            b = int(n / i)
            ans = min(ans, a+b-2)
    print(ans)
        
        
if __name__ == "__main__":
    main()

Solution (Python):
import math
n = int(input())
ans = 10**12
square = math.ceil(math.sqrt(n))+1
for i in range(1,square):
    if n%i == 0:
        ans = min(ans,n/i) 
if ans == 10**12:
    print(n-1)
    exit()	
b = n/ans
print(int(ans+b-2))

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

Solution (Python):
import sys
import itertools
import numpy as np

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

tmp = make_divisors(n)
tmp.sort()
sq = np.sqrt(n)
tmpnum = n
for i in tmp:
    if i > sq:
        break
    else:
        tmpnum = min(tmpnum-1, n//i + i - 2)
print(tmpnum)

Solution (Python):
N = int(input())
m = N
for a in range(1, int(N**(0.5)+2)):
    if N%a == 0:
        m = min(m, a + N//a - 2)
print(m)

Solution (Python):
import math

n = int(input())
ans = 0
a = 1
li = []
while a <= math.sqrt(n):
  b = n // a
  if a * b == n:
    li.append(a + b - 2)
  a += 1  
    
ans = min(li)
print(ans)

Solution (Python):
n=int(input())
ran = int(n**0.5) + 1
ans = 999999999999
for i in range(1, ran):
    j = n // i
    if j != int(n / i):
        continue
    if i * j != n:
        continue
    tmp = i + j - 2
    if tmp < ans:
        ans = tmp
print(ans)

Solution (Python):
M = int(input())

for i in reversed(range(2, int(-(-M**0.5//1))+1)): 
    if M % i == 0: 
        print(int(i + M / i -2))
        exit()
print(M-1)

Solution (Python):
import numpy as np

n = int(input())

a = 1
b = n

ans = n - 1

for i in range(2, int(np.sqrt(n) + 1)):
    if n % i ==  0:
        a = int(i)
        b = int(n / i)
        ans = min(ans, int(a + b - 2))

print(ans)

Solution (Python):
import sys
import math

n = int(input())
ans = 0

for i in range(int(math.sqrt(n)), 0, -1):
    if n%i is 0:
        ans = int(n/i + i - 2)
        break
if ans is not 0:
    print(ans)
else:
    print(n-1)

Solution (Python):
N = int(input())

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

Solution (Python):
n = int(input())
ans = n
for i in range(1,int(n**.5)+2):
  if n%i == 0:
    ans = min(ans, i + n//i - 2)
print(ans)

Solution (Python):
import math

def solv(N):
    x = N-1
    for i in range(1, int(math.sqrt(N)) + 1):
        if N % i == 0:
            x = min(x, i + N / i -2)
    return x

N = int(input())
print(int(solv(N)))

Solution (Python):
N = int(input())
l = []
for i in range(1, 1000001):
    a = N / i
    if a.is_integer():
        l.append(i + N / i)
print(int(min(l) - 2))

Solution (Python):
import math

n = int(input())

result = n + 1
num = int(math.sqrt(n)) + 1

for i in range(2, num):
  if n % i == 0:
    if i + (n/i) < result:
      result = i + (n/i)

print(int(result-2))

Solution (Python):
a=int(input())
divisors = []
for i in range(1, int(a**0.5)+1):
  if a % i == 0:
    divisors.append(i)
    if i != a // i:
      divisors.append(a//i)

c=len(divisors)
if c%2==0:
  print(divisors[c-1]+divisors[c-2]-2)
else:
  print(divisors[c-1]*2-2)

Solution (Python):
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)
            
            divisors.append(n//i)

    return divisors

div = make_divisors(N)

for i in range(len(div)//2):
  a = div[2*i]
  b = div[2*i+1]
  ans = a + b - 2
  if i==0:
    tmp = ans
  else:  
    tmp = min(ans, tmp)
print(tmp)

Solution (Python):
import math
def factorization(n):
    arr = []
    temp = int(math.sqrt(n)+1)
    for i in range(1,temp+1):
      if n % i == 0:
        arr.append(i+n/i-2)

    return arr
  
N = int(input())
A = factorization(N)
print(int(min(A)))

Solution (Python):
import math

n = int(input())
b = 0
list = []
sqrt = math.ceil(math.sqrt(n))
for i in range(1,sqrt+1):
	if(n%i==0):
		b = i
print(b + (n//b) -2)

Solution (Python):
import math
n = int(input())
n_s = int(math.sqrt(n))
for i in range(1, n_s+1):
    if n % i == 0:
        a = i
        b = n / i
        
print(int(a + b - 2))

Solution (Python):
import sys
import math

n = int(input())

cost = sys.maxsize
tmp = 0
k = math.sqrt(n)
for i in range(1,int(k)+1):
    q, mod = divmod(n,i)
    if(mod==0):
        tmp = i + int(q)
        cost = min(tmp,cost)
        tmp = 0

print(cost-2)

Solution (Python):
n = int(input())

ans = n - 1
for i in range(2, n):
    if i * i > n:
        break

    if n % i == 0:
        ans = min(ans, i + n // i - 2)

print(ans)

Solution (Python):
N = float(input())
l = []
for i in range(1,1000001):
  a = N/i
  if a.is_integer():
    l.append(i + N/i)
print(int(min(l)-2))

Solution (Python):

import sys
sys.setrecursionlimit(10000)
INF = 1<<48


def solve(N: int):
    
    def 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

    l = divisors(N)
    l.append(1)
    l.sort()

    ans = INF

    for i in l:
        M = N // i
        ans = min(ans, M+i-2)

    print(ans)

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

if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math

n = int(input())

cost = sys.maxsize
tmp = 0
k = math.sqrt(n)
for i in range(1,int(k)+1):
    q, mod = divmod(n,i)
    if(mod==0):
        tmp = i + int(q) - 2
        cost = min(tmp,cost)
        tmp = 0

print(cost)

Solution (Python):
import math
N = int(input())
N2 =  int(math.sqrt(N))

for i in range(N2,0,-1):
    if(N%i==0):
        print(N//i+i-2)
        exit()

print(N-1)

Solution (Python):
import math

N = int(input())
a = N + 1
b = round(math.sqrt(N))

for i in range(b):
  j = i + 1
  if N % j == 0:
    if a > j + N / j:
      a = j + N / j
print(round(a) - 2)

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

Solution (Python):
import math
N=int(input())

D=int(math.sqrt(N))
for i in reversed(range(1,D+1)):
    if(N%i==0):
        print(int(i+N/i-2))
        exit(0)

Solution (Python):

import numpy as np

n = int(input())

now_min = n
now_min_dex = 1
for i in range(1,int(np.ceil(np.sqrt(n)))+1):

    if n % i == 0:
        
        tmp = (i + n // i)

        if now_min > tmp:
            
            now_min = tmp
            now_min_dex = i

if now_min_dex == 1:
    print(now_min - 1)
else:
    print(now_min - 2)

Solution (Python):
import math
N = int(input())

def eval_ab(a, b):
    if a == 1 or b == 1:
        return a + b - 1
    else:
        return a + b - 2
    
min_e = N - 1
a = int(math.sqrt(N)) + 2
for i in range(1, a):

    if N % i == 0:
        j = N // i
        e = eval_ab(i, j)
        min_e = min(e, min_e)

print(min_e)

Solution (Python):
n = int(input())
i = 1
ans = n
 
while i * i <= n:
    j, m = divmod(n, i)
    if m == 0:
        ans = min(ans, i + j - 2)
    i += 1
 
print(ans)

Solution (Python):
import numpy as np

N = int(input())
for i in range(int(np.sqrt(N)), 0, -1) :
  if N%i == 0 :
    print(int(N/i)+i-2)
    exit()

print(N-1)

Solution (Python):

if __name__ == '__main__':
    N = int(input())
    res = 1
    for i in range(2, int(N**.5)+1):
        if N % i == 0:
            res = i
    print(res + N//res - 2)

Solution (Python):
import math
N = int(input())
for i in range(int(math.sqrt(N)), 0, -1):
  if N / i == int(N / i):
      print(int(N / i + i - 2))
      exit()

Solution (Python):
n = int(input())
mn = 10**12
for i in range(1, int((n ** 0.5)) + 1):
    if n / i == n // i:
        mn = min(mn, i + n//i - 2)
print(mn)

Solution (Python):








import math

def divisor(M):
    maxX = int(math.sqrt(M))
    for x in range(2, maxX + 1):
        if M % x == 0:
            return x, M // x
    return 1, M


N = int(input().strip())
N_sqrt = int(math.sqrt(N))

ret_list = []
for a in range(1, N_sqrt + 1):
    if N % a == 0:
        ret_list.append(a + N // a - 2)

print(min(ret_list))

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

Solution (Python):
n=int(input())
ans=n
for i in range(1,int(n**0.5)+1):
    if n%i==0:
        ans=min(ans,i+n//i-2)
print(ans)

Solution (Python):
n = int(input())
ans = float('inf')
for i in range(1,10**6+1):
    if n/i == int(n/i):
        ans = min(ans, i-1 + n//i-1)
print(ans)

Solution (Python):
N = int(input())
n = int(N**0.5) + 1
a, b = 0, 0


for i in range(n, 1, -1):
  if N % i == 0:
    a, b = N // i, i
    break

if a == 0:
  a, b = N, 1

print(a + b - 2)

Solution (Python):

N = int(input())

factor = []

a = int(N**0.5)+1

l = []
for i in range(a):
    if N%(i+1) == 0:
        l.append(i+1)

b = max(l)

print(N//b + b -2)

Solution (Python):
num = 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

numDivList = make_divisors(num)
midNum = len(numDivList) // 2

ans = 0
if len(numDivList) % 2 == 0:
	ans = numDivList[midNum-1] + numDivList[midNum] -2
else:
	ans = numDivList[midNum] * 2 -2

print(ans)

Solution (Python):
import math
n = int(input())

answer = n - 1

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

print(answer)

Solution (Python):
N = int(input())
ans = 10 ** 19
for i in range(1, int(N**.5) + 1):
  if N % i == 0:
    ans = min(ans, i + N // i -2)
print(ans)

Solution (Python):
import math
N=int(input())
m=N+1
for j in range(2,int(math.sqrt(N))+1):
    if N%j==0:
        a=j
        b=N//j
        if a>b:
            break
        else:
            m=min(m,(a+b))

print(m-2)

Solution (Python):
n=int(input())
ans=10**12
for i in range(int(n**0.5)+1):
    a=i+1
    b=n//a
    if a*b==n:
        ans=min(ans,a+b-2)
print(ans)

Solution (Python):
n = int(input())
ans = 1000000000000
for i in range(1, int(n ** 0.5) + 1):
    if n % i == 0:
        a = i
        b = n // i
        ans = min(ans, a + b - 2)
print(ans)

Solution (Python):
n=int(input())
a=10**12
for i in range(1,int(n**0.5)+2):
    if n%i==0:
        a=min(a,i+n//i-2)
print(a)

Solution (Python):
N = int(input())
ans = []

for i in range(1, int(pow(N, 0.5))+1):
    if N % i == 0:
        j = N // i
        ans.append(i-1+j-1)

print(min(ans))

Solution (Python):
import sys
import numpy as np
N = int(input())
for i in range(int(np.sqrt(N)), 0, -1):
  if N / i == int(N / i):
      print(int(N / i + i - 2))
      sys.exit()
print(N - 1)

Solution (Python):

import math
n = int(input())
n_s = int(math.sqrt(n))
for i in range(1, n_s+1):
    if n % i == 0:
        a = i
        b = n / i
        
print(int(a + b - 2))

Solution (Python):
import numpy as np
N = int(input())

max_val1 = 0
max_val2 = 0
ans = 0
ans_temp = 1000000000000
for i in range(1, int(np.sqrt(N))+1):
    if N % i == 0:
        max_val1 = i
        max_val2 = N // i
        ans = max_val1 + max_val2 - 2
        if ans < ans_temp:
            ans_temp = ans
        else:
            break
        
        
        


print(ans)

Solution (Python):



import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
ans = inf
for i in range(1,int(math.sqrt(n)+1)):
    if n % i == 0:
        ans = min(ans,i + n//i)
print(ans-2)

Solution (Python):
import math
 
A = int(input())
 
start = math.ceil(math.pow(A, 0.5))
while A % start != 0:
    start -= 1
 
print((start + (A // start) - 2))

Solution (Python):
import itertools

a = int(input())

def md(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

ab = [[i,a//i] for i in md(a)]
abc = [sum(ab[i]) for i in range(len(ab))]

print(min(abc)-2)

Solution (Python):
N = int(input())
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

a = make_divisors(N)
if len(a)%2 == 1:
  print(2*int(math.sqrt(N))-2)
if len(a)%2 == 0:
  b = a[len(a)//2-1]
  c = a[len(a)//2]
  print(b+c-2)

Solution (Python):
N = int(input())
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

a = make_divisors(N)
if len(a)%2 == 1:
  print(2*int(math.sqrt(N))-2)
if len(a)%2 == 0:
  b = a[int(len(a)/2)-1]
  c = a[int(len(a)/2)]
  print(b+c-2)

Solution (Python):
import sys
import numpy as np
N = int(input())
for i in range(int(np.sqrt(N)), 0, -1):
  if N / i == int(N / i):
      print(int(N / i + i - 2))
      sys.exit()
print(N - 1)

Solution (Python):


import numpy as np
N = int(input())

first_num = 0
second_num = 0
min_diff = N
for i in range(1, int(np.sqrt(N) + 1)):
    now_diff = N // i - i
    if N % i == 0 and min_diff > now_diff:
        first_num = i
        second_num = N // i
        min_diff = now_diff
print(max(first_num + second_num - 2, 0))

Solution (Python):
import math

a = int(input())
list = []
sqrt = math.ceil(math.sqrt(a))
for i in range(sqrt):
  if (a%(i+1)==0):
    list.append(i+1)
b = max(list)
c = round(a/b)
print(b + c -2)

Solution (Python):
import math
N = int(input())
ans = N-1
n = math.sqrt(N)
n = int(n)+1
for i in range(1, n):
    if N%i==0:
        tmp = N//i
        ans = (tmp-1)+(i-1)

    
print(ans)

Solution (Python):
N = int(input())
a = 0
ans = N-1
s = 0
for x in range(1,1000001):
    s=N//x
    if N%x==0:
        a = (s-1)+(x-1)
        if ans>a:
             ans = a
print(ans)

Solution (Python):
import math

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

l = make_divisors(n)
n = len(l)
ans = []
for i in range(n):
	ans.append(l[i] + l[n-i-1])

print(min(ans)-2)

Solution (Python):


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


def main():
    N = int(input())
    V = make_divisors(N)
    if len(V) %2 == 1:
        
        print(V[-1]*2-2)
        exit()
    
    print(sum(V[-2:])-2)
        
if __name__ == '__main__':
    main()

Solution (Python):
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
N_list = make_divisors(N) 

if N_list[-1]*N_list[-2] == N:
    print(N_list[-1]+N_list[-2]-2)
else:
    print(N_list[-1]+N_list[-1]-2)

Solution (Python):
n = int(input())
ans = 10**13    

for i in range(1,10**7):
  if (n % i) == 0: 
    j = n / i
    ans_ = ((i + j) - 2)
    if ans > ans_:
      ans = ans_
print(int(ans))

Solution (Python):
import numpy as np
N = int(input())
res = float('inf')
for n in range(1, int(np.sqrt(N))+1):
    if N % n == 0:
        t = N/n
        res = int(min(res, n+t))
print(res-2)

Solution (Python):
import math
x = int(input())
x_sqrt = int(math.sqrt(x))

min_num = x-1
for i in range(2,x_sqrt+2):
    if x % i == 0:
        num = i+int(x/i)-2
        if num < min_num:
            min_num = num
print(min_num)

Solution (Python):

import math
N=int(input())
int_root_N=int(math.sqrt(N))
for i in range(int_root_N,0,-1):
    if N%i==0:
        min_n=i
        break

print(min_n-1+N//min_n-1)

Solution (Python):
import math
def anss(n):
    div = []
    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0:
            if n == i * i:
                div.append(i)
            else:
                div.append(i)
                div.append(n // i)
    div.sort()
    if len(div) % 2:
        return 2 * (div[len(div)// 2] - 1)
    else:
        return div[len(div) // 2] - 1 + div[(len(div) // 2) - 1] - 1
n = int(input())
print(anss(n))

Solution (Python):
n = int(input())
move =[]
for i in range(1, int(n**0.5)+1):
    if n % i == 0:
        move.append(i+n//i)

print(min(move)-2)

Solution (Python):
import math

a=int(input())
x=(math.ceil(a**(1/2)))
for i in range(x+1):
 if a%(x-i+1)==0:
  print(int(x-i-1+(a/(x-i+1))))
  break

Solution (Python):
N = int(input())
import math
def is_prime(n):
  if n == 1: return False
  for k in range(2, int(math.sqrt(n)) + 1):
    if n % k == 0:
      return False
  return True
if is_prime(N):
  print(N-1)
else:
  a = math.floor(math.sqrt(N))
  while True:
    if N%a==0:
      break
    a=a-1
  print(int(a+N/a-2))

Solution (Python):
N=int(input())
p=0
for i in range(1,N):
  if i**2<=N:
    p=p+1
  else:
    break
    
q=p   
for i in reversed(range(p+1)):
  if N%i!=0:
    q=q-1
  else:
    break
    
print((q+(N//q))-2)

Solution (Python):
import math

def make_divisors(n):
  divisors = []
  for i in range(1, int(math.sqrt(n))+1):
    if n % i == 0:
      x = i
      y = n // i
      divisors.append([x, y])

  return divisors

def list_sum(t_list):
  return t_list[0] + t_list[1]

n = int(input())
yakusu = make_divisors(n)

data = list(map(list_sum, yakusu))
print(min(data) - 2)

Solution (Python):
import math
n = int(input())
x = range(1,math.ceil(n**0.5)+1,1)
b = []
for a in x:
    if n % a == 0:
        y = n//a
        b.append(y)
b_min = min(b)
a = n // b_min
sum = a+b_min-2
print(sum)

Solution (Python):
N=int(input())
M=int(N**0.5)
L=0

for i in range(1,M+1):
	j=M-(i-1)
	if N%j==0:
		L=j-1+N/j-1
		break

print(int(L))

Solution (Python):
n = int(input())
i = int(n ** 0.5)
while i > 0:
	if n % i == 0:
		print(int(i + (n/i) - 2))
		break
	else:
		i -= 1

Solution (Python):
import math
N = int(input())
x = math.floor(math.sqrt(N))
y = 0
for i in reversed(range(1, x+1)):
    if N % i == 0:
        y = i
        break
    else:
        continue
ans = y + (N/y) - 2
print(int(ans))

Solution (Python):
import math
n = int(input())
result = [0,0]
for i in range(1, int(math.sqrt(n))+1):
    if not n%i:
        result = [n/i,i]
print(int(sum(result)-2))

Solution (Python):
import math
n=int(input())
m=math.sqrt(n)
m=math.floor(m)+1
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)

Solution (Python):
N=int(input())
n=round(N**(1/2))
for i in range(1,n+2):
	if N/i==N//i:
		ans=i+N/i-2
print(int(ans))

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())

U = 10**6 + 100
x = np.arange(1,U,dtype=np.int64)
div = x[N%x==0]
answer = (div + (N//div)).min() - 2
print(answer)

Solution (Python):

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

Solution (Python):
n=int(input())
l=1
for i in range(1,int(n**0.5)+1):
	if n%i==0:
		l=i
k=n//l
print(l+k-2)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())

U = 10**6 + 100
div = np.arange(1,U,dtype=np.int64)
div = div[N%div==0]
answer = (div + (N//div)).min() - 2
print(answer)

Solution (Python):
N = int(input())
S = N+1
from math import sqrt
for a in range(int(sqrt(N))+2, 0, -1):
    b, y = divmod(N, a)
    if y != 0:
        continue
    S = min(S, a+b)
print(S-2)

Solution (Python):
N=int(input())
import math
A=math.sqrt(N)
B=math.floor(A) 
while True:
    if N % B == 0 :
        print(B+N//B-2)
        break
    else :
        B-=1
        continue

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())

U = 10**6 + 100
div = np.arange(1,U,dtype=np.int64)
div = div[N%div==0]
answer = (div + (N//div)).min() - 2
print(answer)

Solution (Python):
N = int(input())
ans = 10**13
for i in range(1,int(N**0.5)+1) :
    if N % i == 0 :
        if i == 1 :
            ans = min(ans, i+(N//i)-2)
        else :
            ans = min(ans, i+(N//i)-2)
print(ans)

Solution (Python):
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)
divisors.sort()
p = len(divisors)//2


if len(divisors)%2 > 0:
  print (divisors[p] + divisors[p] -2)
else:
  print (divisors[p] + divisors[p -1] -2)

Solution (Python):


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 = n**0.5
for i in range(len(list)-1):
    if (list[i] <= root and list[i+1] >root):
        a = list[i]
b = n //a
print(a+b-2)

Solution (Python):
def make_divisors(n):
    ans = float('inf')
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ans = min(ans, i+N//i-2)
            if i != n // i:
                ans = min(ans, n//i+N//(n//i)-2)

    return ans

N = int(input())
print(make_divisors(N))

Solution (Python):
n=int(input())
a = []
for i in range(1, int(n**0.5)+1):
  if n % i == 0:
    a.append(i)
    if i != n // i:
      a.append(n//i)
b = list(map(int,a))
anc =1000000000000
for l in range(len(b)):
  if int(n/b[l]+b[l])-2<anc:
    anc = int(n/b[l]+b[l])-2
print(anc)