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):
import sys, math
input = sys.stdin.readline

def main():
    N = int(input())
    yaku = []
    for i in range(int(math.sqrt(N))+1, 0, -1):
        if N%i == 0:
            t = N//i
            print(i+t-2)
            return



if __name__ == "__main__":
    main()

Solution (Python):
import math

n = int(input())

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

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

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

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

Solution (Python):
n=int(input())
k=list()
for i in range(int(n**0.5)):
  if n%(i+1)==0:
    k.append(int(i+n/(i+1)-1))
print(min(k))

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

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

Solution (Python):
from math import sqrt

N = int(input())

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

Solution (Python):
from math import sqrt

N = int(input())

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

Solution (Python):
import time
st_time=time.time()

from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
ts=time.time()
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
show_flg=False
show_flg=True


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


print(a+b-2)

Solution (Python):
n = int(input())
ans = n - 1

for i in range(1, int(n ** 0.5) + 1):
  if n % i == 0:
    ans = (i - 1) + (n // i - 1)

print(ans)

Solution (Python):
num = int(input())
ans = 10**12
for a in range(1,int(num**0.5)+1):
    if num % a == 0 and ans > (num // a) + a:
        ans = (num // a) + a 
print(ans-2)

Solution (Python):
ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(map(int, input().split()))

import numpy as np
import math

n = ii()

sq = math.ceil(math.sqrt(n))

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


print(ans-2)

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


min=10**12
for i in range(int(N**0.5)):
 if (N % (i+1))==0 and min>((N//(i+1))+i+1):
    min=(N//(i+1))+i+1
  
print(min-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+n//i)

    return divisors
  
print(min(make_divisors(N))-2)

Solution (Python):
from math import sqrt 
a = int(input())
ans = a*a
for i in range(1,int(sqrt(a))+1):
  if a % i == 0:
    tmp = a/i + i - 2
    if tmp < ans:
      ans = tmp
print(int(ans))

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

import math
    
A = int(math.sqrt(N))
while N % A > 0:
    A -= 1
    continue

print(A + N // A - 2)

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

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)
    divisors.sort()
    return divisors

N = int(input())
divs = make_divisors(N)
ans = float('inf')
for i in divs:
    j = N//i
    ans = min(ans, i+j-2)
print(ans)

Solution (Python):
import math

N = int(input())

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

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

Solution (Python):
import math

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

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

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

if __name__ == "__main__":
    main()

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)

    divisors.sort()
    return divisors


N = int(input())
cand = make_divisors(N)

ans = []
for c in cand:
    ans.append((N//c - 1) + c - 1)

print(min(ans))

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

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

Solution (Python):
import math

N = int(input())

ans = 1e12
for a in range(1, int(math.sqrt(N)) + 2):
    if N % a == 0:
        b = N // a
        ans = min(ans,a+b-2)

print(ans)

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

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

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

for i in range(1, int(n**.5)+1):
  if n%i == 0:
    p = i

q = n//p

print(p+q-2)

Solution (Python):
from math import sqrt, ceil

N = int(input())

minSteps = N - 1
for i in range(1, int(ceil(sqrt(N))) + 1):
    if N % i == 0:
        y = N // i
        minSteps = min(minSteps, i - 1 + y - 1)

print(minSteps)

Solution (Python):
import math
n=int(input())
mi=9999999999999
a=math.ceil(math.sqrt(n))
for i in range(1,a+1):
    x=n/i
    if x.is_integer():
        a=x+i-2
    if a<mi:
        mi=a
print(int(a))

Solution (Python):
inf = float('inf')
N = int(input())

from math import floor


def divisor(n):
    left = [1]
    right = [n]
    sup = floor(pow(n,1/2))
    for p in range(2,sup+1):
        if n % p == 0:
            left.append(p)
            right.append(n//p)
    return left, right

ans = inf
left, right = divisor(N)
for i, j in zip(left, right):
    d = abs(i-1) + abs(j-1)
    ans = min(ans, d)

print(ans)

Solution (Python):
import math
min = 1000000000000

n = int(input())
for i in range(1, math.ceil(math.sqrt(n))+1):
    x = n / i
    if x.is_integer():
        ans = (x-1) + (i-1)
        if ans < min:
            min = ans

print(int(ans))

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

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

Solution (Python):
import math

n = int(input())

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

for i in range(m):
    p,q = divmod(n,m-i)
    if q == 0:
        print((m-i) + p - 2)
        break

Solution (Python):
def is_square(n):
    return n % (n**0.5) == 0

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())
if is_square(n): print(int(n**0.5*2-2))
else:
    res = make_divisors(n)
    print(res[len(res)//2-1]+res[len(res)//2]-2)

Solution (Python):
N = int(input())
i = 1
res = N
while i ** 2 <= N:
  if N % i == 0:
    q = N // i
    res = min(res, q - 1 + i - 1)
  
  i += 1
print(res)

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)

    divisors.sort()
    return divisors

N = int(input())
divisors = make_divisors(N)
memo = 0
maX = divisors[0] + divisors[len(divisors) - 1]
for (i, r) in zip(divisors, reversed(divisors)):
    maX = min(i + r, maX)
    memo = i
    if memo == r:
        break
print(maX - 2)

Solution (Python):
words = lambda t : list(map(t, input().split()))
n = int(input())

ans = n-1
i = 1
while i*i <= n:
    if n % i == 0:
        
        ans = min(ans, i + n//i - 2)
    i+=1
print(ans)

Solution (Python):
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

N = int(stdin.readline().rstrip())

move_i = 0
move_j = 0

result = []

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

ans = min(result) 

print(ans)

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

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

Solution (Python):
from math import sqrt

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

Solution (Python):
data = input()
num = int(data)
sq = int(num**(1/2))
for i in range(sq, 0, -1):
    if num%i == 0:
        ans = i + num/i -2
        print(int(ans))
        break

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

def ceil(x):
    return int(-(-x//1))

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

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

i = 1
while i <= a // i:
    i += 1

while a % i != 0:
    i -= 1

print(i + a//i - 2)

Solution (Python):
N = int(input())
n = 1
last = 0
while n**2 <= N:
  if N%n == 0 :
    last = n
  n += 1
print(last + N//last - 2)

Solution (Python):
import math
s = input().split() 
n = int(s[0])
root = int(math.sqrt(n))
ans = 10**18
for i in range(1, root + 1):
    if n % i != 0:
        continue
    j = n / i
    ans = min(ans, i + j - 2)
print(int(ans))

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

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

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

N = int(read())

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

Solution (Python):
import numpy as np

N = int(input())
N_sqrt = int(np.sqrt(N))+1
N_ = [i for i in range(2, N_sqrt) if N % i == 0]

if len(N_) == 0:
    print(N-1)
else:
    pair = [(i, int(N/i)) for i in N_]
    my_lambda = lambda x : sum(x)
    x = list(map(my_lambda, pair))
    print(min(x)-2)

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

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

Solution (Python):
from sys import stdin
import math
N = int(input())
a,b = 0,0
for i in range(int(math.sqrt(N)),0,-1):
    if N % i == 0:
        a = i
        b = N // a
        break
print(a+b-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

n = int(input())

li = make_divisors(n)

ans = 10 ** 10

for i in li:
    j = n // i
    ans = min(ans,i + j)

print(i + j - 2)

Solution (Python):
import math

a = int(input())
flag = False
result = 1e13
for i in range(2, int(math.sqrt(a)) + 1):
    if a % i == 0:
        flag = True
        result = min(result, i + int(a / i) - 2)
if not flag:
    print(a - 1)
else:
    print(result)

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

Solution (Python):
import sys
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *

from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def divisor_pairs(n):
    res = set()
    for i in range(1, int(n**0.5)+1):
        if n%i == 0:
            a,b = i,n//i
            res.add((a,b))
    res = list(res)
    res.sort()
    return res

def main():
    """ main """
    N = int(input())
    pairs = divisor_pairs(N)
    ans = float('inf')
    for x,y in pairs:
        ans = min(ans,abs(x-1)+abs(y-1))

    print(ans)

if __name__ == '__main__':
    main()

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

print(ans)

Solution (Python):
import sys
import math
input  = sys.stdin.readline
 
N = int(input())
chk = math.floor(math.sqrt(N))
for i in range(chk, 0, -1):
  a = i
  if N%a != 0:
    continue
  b = N/a
  print(int(a+b-2))
  break

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

d=make_divisors(n)


count=0
ans=[]
for i in d:
    pair=n//i
    count=(pair-1)+(i-1)
    ans.append(count)

print(min(ans))

Solution (Python):
import sys
from collections import defaultdict, deque
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]



def A():
    return



def B():
    return



def C():
    n = I()
    for i in range(int(n ** 0.5), 0, -1):
        if n % i == 0:
            print(i + n // i - 2)
            return
    return



def D():
    return



def E():
    return



def F():
    return



def resolve():
    C()
    return



if __name__ == "__main__":
    C()

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

print(data)

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

Solution (Python):
N = int(input())
root = int(N**0.5)

pairs = [[i, N //i] for i in range(1, root+1) if N % i == 0]

move = min([pair[0] + pair[1] -2 for pair in pairs])
print(move)

Solution (Python):


a = int(input())
sum = []
result = 0

ub = int(pow(a, 0.5)) + 1

for i in range(2, ub):  
  (d, mod) = divmod(a, i)
  if mod == 0:
    sum.append(i + d)

if len(sum) == 0:
  print(a - 1)
else:
  sum.sort()
  print(sum[0] - 2)

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

for i in range(1, n):
    if i*i > n:
        break
    if n%i == 0:
        fct1, fct2 = i, n//i
        ans = min(ans, abs(i-1) + abs(1 - n//i))

print(ans)

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

for i in range(1,int(N ** 0.5)+1):
  if N % i == 0:
    L.append(i + N // i)
print (min(L)-2)

Solution (Python):
n = int(input())
r_n = int(n**0.5)
ans = float('inf')
for i in range(1,r_n+1):
  if n%i!=0:
    continue
  j = n/i
  ans = min(ans,i+j-2)  
print(int(ans))

Solution (Python):
input_number = int(input())
walk_count = int(1000000000000)
number_list_A = range(1,1000001)


for a in number_list_A:
	if input_number % a == 0:
		b = input_number / a
		new_walk_count = int(a + b - 2)
	if new_walk_count < walk_count:
		walk_count = new_walk_count
	new_walk_count = 1000000000000

print(walk_count)

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

class Kake:
    def __init__(self, n):
        self.n = n

    def div(self):
        div_dict = {}
        
        for i in range(1, int(self.n**0.5)+1):
            if self.n % i == 0 and i <= (self.n/i):
                div_dict[i] = int(self.n / i)     
    
        sa_list = list()
        for i in div_dict:
            sa_list.append((i-1)+(div_dict[i]-1))
        print(min(sa_list))
         
kake = Kake(n)
kake.div()

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




a=0
b=0
c=N+1


for i in range(1,int(N**0.5)+1):
    if N%i==0:
        a=i
        b=N/i
        
        
        c=min([c, a+b])
        
        

c=int(c-2)
print(c)

Solution (Python):
N = int(input())
A = []
n = N ** 0.5
p = int(n)

for i in range(1, p + 1):
	if N % i == 0 and i <= n:
		A.append(i)
		
a = int(max(A))
b = int(N / a)
print(a + b - 2)

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

Solution (Python):
from math import sqrt, ceil
n = int(input())

distance = 10**13
for i in range(1, ceil(sqrt(n)) + 1):
    if n % i == 0:
        new_distance = n//i + i
        if new_distance < distance:
            distance = new_distance

print(distance - 2)

Solution (Python):


import math


N = int(input())

sN = math.floor(math.sqrt(N))
      
for i in range(sN) :
  if N % (sN - i) == 0 :
    print( int((sN - i - 1) + ((N / (sN - i)) - 1)) )
    break

Solution (Python):
import math
res = 10**12
n = int(input())
for i in range(1, int(math.sqrt(n)) + 1):
  q, mod = divmod(n, i)
  if(mod == 0):
    res = min([res, (i-1) + (q-1)])
print(res)

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

Solution (Python):
import math


def get_input():
    return int(input())


def main():
    N = get_input()

    sqrt_n = int(math.sqrt(N))
    minimum = N + 1
    for p in range(1, sqrt_n + 1):
        if N % p == 0:
            q = N / p
            if p + q < minimum:
                minimum = int(p + q)

    print(minimum - 2)


main()

Solution (Python):
import sys
input = sys.stdin.readline
def print_ans(input_line):
    """Test Case
    >>> print_ans("10")
    5
    >>> print_ans("50")
    13
    >>> print_ans("10000000019")
    10000000018
    """
    N = int(input_line)
    min_ans = N - 1
    for i in range(1,int(N ** 0.5) + 1):
        q, mod= divmod(N,i)
        if mod == 0:
            min_ans = min(min_ans, q + i -2 )
    print(min_ans)

if __name__ == '__main__':
    print_ans(input())

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

s = int(n**0.5)
temp = n
li = [1]

for i in range(s+1,0,-1):
    if temp%i == 0:
        li.append(i)
        break

t = n//li[-1]

print((t-1) + (li[-1]-1))

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

def ij(x):
    for i in range(x, 0, -1):
        if n/i == n//i:
            return i, n//i

print(sum(ij(int(sqrt(n)))) - 2)

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

def ij(x):
    for i in range(x):
        i = x - i
        if n / i == n//i:
            return i, n//i

print(sum(ij(int(sqrt(n)))) - 2)

Solution (Python):

"""
Created on Wed Nov  6 21:49:38 2019

@author: over-
"""

N=int(input())

ans=N
for i in range(1,10**12):
    if i**2 > N: break
    if N%i == 0:
        A=(N/i-1)+(i-1)
        if A < ans:
            ans = A
            
print(int(A))

Solution (Python):
tall = int(input())
bit = int(tall**(1/2))
while ((tall/bit)%1 != 0):
  bit -= 1
print(int(bit+tall/bit-2))

Solution (Python):
data=int(input())
sum=10**12
 
for i in range(10**6):
  a=i+1
  if data%a==0:
    b=data//a
    if a+b<sum:
      sum=a+b
      
print(sum-2)

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

min_step = 10**12

i = 1
j = 1
l = int(n**0.5)+1

for p in range(1, l+1):
    if n % p == 0:
        if i == (n / p) and j == p:
            break
        step = (p + n / p) - 2
        if min_step > step:
            min_step = step
            i = p
            j = (n / p)

print(int(min_step))

Solution (Python):
a = int(input())
b = 0
l = int(a**0.5)+1
count = 0
for i in range(l):
    i = i+1
    if a%i == 0:
        j = a//i
    if i*j == a:
        if count == 0:
            count += 1
            c = i
            d = j
        if count>0:
            if (c+d)>(i+j):
                c = i
                d = j
ans = c+d-2
print(ans)

Solution (Python):
N=int(input())
goal=[]
step=[]
i=1
while i*i<=N:
     if N%i==0:
          j=N/i
          goal.append([i,j])
     i+=1
n=len(goal)
for i in range(n):
     step.append(goal[i][0]-1+goal[i][1]-1)
print(int(min((step))))

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

Solution (Python):
n=int(input())
k=int(n**(1/2))

for i in range(k):
    l=k-i
    if n%l==0:
        print(l+int(n/l)-2)
        break

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

Solution (Python):
n = int(input())
ans = n-1

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

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

Solution (Python):

n = int(input())

x = 1
y = n

for i in reversed(range(1, int(n**0.5)+1)):
    if n % i == 0:
        x = i
        y = n / i
        break


print(int(x+y) - 2)

Solution (Python):
def solve(n):
    ans = int(1e12)
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0 and i + n // i - 2 < ans:
            ans = i + n // i - 2
    return int(ans)


num = int(input())
print(solve(num))

Solution (Python):
n = int(input())
sum_list = []

for x in range(1, int(n ** 0.5) + 1):
    if n % x == 0 :
        sum_list.append(int(x + n / x - 2))

print(min(sum_list))

Solution (Python):
n = int(input())
for i in range(1,int(n**(1/2)+1))[::-1]:
    if not n%i:
        j = n//i 
        print(i-1+j-1)
        break

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

import math

s=int(math.sqrt(n))

for i in range(s):
  if n%(s-i)==0:
    k1=s-i
    break

  else:
    k=0


k2=int(n/k1)

print(k1+k2-2)

Solution (Python):
import math

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

print(min(ans))

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

ans_sum = []
for i in range(1, round(math.sqrt(n) + 2)):
    if n%i == 0:
        ans_sum.append(i-1 + (n//i) -1)

print(min(ans_sum))

Solution (Python):
import math
n = int(input())
sum_ij = 1000000000000
sq_n = int(math.sqrt(n))
for i in range(1, sq_n+1):
  if (n%i==0):
    j = int(n/i)
    if(i+j < sum_ij):
      sum_ij = i+j-2
print(int(sum_ij))

Solution (Python):
import math
n = int(input())
sum_ij = 1000000000000
sq_n = int(math.sqrt(n))
for i in range(1, sq_n+1):
  if (n%i==0):
    j = int(n/i)
    if(i+j < sum_ij):
      sum_ij = i+j-2
print(int(sum_ij))

Solution (Python):
N = int(input())
i = 1
ans = N
while (i ** 2 <= N):
  if (N % i == 0):
    ans = min(ans, N // i + i - 2)
  i += 1

print(ans)

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

divisors = listDivisors(n)

if len(divisors) % 2 == 1:
    a = divisors[-1]
    b = divisors[-1]
else :
    a = divisors[-1]
    b = divisors[-2]
    
answer = a + b - 2

print(answer)

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 math
n = int(input())
m = math.sqrt(n)
m = math.floor(m)
ans = 10000000000000
for i in range(1,m+1):
    if n%i == 0:
        ans = min(ans,i-1 + n/i - 1)
ans = int(ans)
print(ans)

Solution (Python):
n = int(input())
rn = int(n**0.5)+1
flag = True
ans = 0
while flag:
    if n%rn == 0:
        ans = rn + n//rn -2
        flag = False
    rn -= 1
print(ans)

Solution (Python):
import math

N=int(input()) 
ans=N-1
for i in range(int(N**0.5), 1, -1):
  a=N//i
  if (a*i==N):
    if (a-1+i-1<ans):
      ans=a-1+i-1

print(ans)

Solution (Python):
from math import sqrt, floor

n = int(input())
t = floor(sqrt(n))

while n % t != 0:
    t -= 1

print(t + n // t - 2)

Solution (Python):

def prime_factorization(N):
    tmp = N
    ans = []
    for i in range(2, int(N ** 0.5) + 1):
        count = 0
        while tmp % i == 0:
            tmp //= i
            count += 1
        if count != 0:
            ans.append([i, count])
    if tmp != 1:
        ans.append([tmp, 1])
    if ans == []:
        ans.append([N, 1])
    return ans

N = int(input())
prime_N = prime_factorization(N)
if len(prime_N) == 1 and prime_N[0][1] == 1:
    print(N - 1)
    exit()
start = int(N ** 0.5) + 1
ans_a = 0
ans_b = 0
for a in range(start, 1, -1):
    b = N // a
    if N == a * b:
        ans_a = a
        ans_b = b
        break

print(ans_a + ans_b - 2)

Solution (Python):


import numpy as np

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

Solution (Python):



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

Solution (Python):
import math

n=int(input())
num=math.ceil(math.sqrt(n))

c=n+2
for i in range(1,num+1):
      if n%i==0 and (i+n//i)<c:
            a=i
            b=n//i
            c=a+b

print(a+b-2)

Solution (Python):
import math
a = int(input())
b = math.ceil(math.sqrt(a))
ans = 10000000000000000

for i in range(1,b+1):
    if a % i == 0:
        if a // i + i - 2 < ans:
            ans = a // i + i - 2

print(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
div=np.arange(1,U,dtype=np.int64)


div=div[N%div==0]


div=div+N//div-2
print(div.min())

Solution (Python):
import math
a = int(input())
result = 0

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

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]
print((div+N//div).min()-2)

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

Solution (Python):

import math


def main():
    N = input_line(int)
    border = int(math.sqrt(N))
    for i in range(border, 0, -1):
        if N % i == 0:
            print((i-1) + (N // i - 1))
            break


def input_line(*types):
    if len(types) == 1:
        return types[0](input())
    else:
        return [t(x) for t, x in zip(types, input().split())]


if __name__ == "__main__":
    main()

Solution (Python):
import math
N = int(input())
m = math.ceil(math.sqrt(N))
ans = N
for i in range(1, m + 1):
    if N % i == 0:
        a = i
        b = N/i
        ans = min(ans, a + b - 2)

print(int(ans))

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

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

Solution (Python):
from math import sqrt

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

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

rN=int(math.sqrt(N))

ans=8101919114514
for i in range(rN):
  i=i+1
  if N%i==0:
    tmp=N/i
    if tmp<ans:
      
      ans=i+tmp-2
print(int(ans))

Solution (Python):
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(int(i+n/i-2))
    return divisors
ans = float("inf")
for i in make_divisors(int(input())):
    
    ans = min(ans,i)
print(ans)

Solution (Python):
import math
n =int(input())
ar = range(1,int(math.sqrt(n))+1)
distance = n
for factor1 in ar:
  if n%factor1 == 0:
    factor2 = int(n/factor1)
    distance = min(distance,factor1+factor2-2)
print(distance)

Solution (Python):
import math

N = int(input())

flag = True
s = math.floor(math.sqrt(N))
for i in range(s, 1, -1):
    if N % i == 0:
        ii = N // i
        print(i - 1 + ii - 1)
        flag = False
        break
if flag:
    print(N - 1)

Solution (Python):
import math

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

Solution (Python):

import math



n = int(input())
ans = n-1

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

print(ans)

Solution (Python):
from math import sqrt

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

Solution (Python):
from math import *

n = int(input())

mn = n

i1 = 0
i2 = n

for i in range(1,ceil(sqrt(n))+1):
    
    if(n%i==0):
        k = n//i
        if(abs(k-i)<mn):
            i1 = i
            i2 = k
            
ans = i1 + i2 -2

print(ans)

Solution (Python):
from math import sqrt

n=int(input())
a=int(sqrt(n))
d=[]
for i in range(1,a+1):
    if n//i==n/i:
        d.extend([i,n//i])

print(d[-1]+d[-2]-2)

Solution (Python):
def p_a():
    A, B = map(int, input().split())
    print(A * B if A < 10 and B < 10 else -1)


def p_b():
    N = int(input())
    for i in range(1, 10):
        for j in range(1, 10):
            if N == i * j:
                print("Yes")
                exit()
    print("No")


import math


def p_c():
    N = int(input())
    m = int(math.sqrt(N))

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


def p_d():
    pass


def p_e():
    pass


def p_f():
    pass


if __name__ == '__main__':
    p_c()

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

ans = N-1
for p in range(2,int(N**0.5)+1):
    if N%p ==0:
        ans = min(ans,N//p + p -2)

print(ans)