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
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s
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


n = load()

ps = []
for i in range(1, int(math.sqrt(n))+1):
    if n % i ==0:
        ps.append((i, int(n/i)))
if not ps:
    print(n-1)
    exit()
mn = min(ps, key=lambda p: p[0] + p[1])
print(mn[0]-1 + mn[1]-1)

Solution (Python):
def func(N):
    loop = int(N ** 0.5)

    ans = float("inf")
    for i in range(1, loop + 1):
        if N % i:
            continue
        j = N // i
        tmp = i + j - 2
        ans = min(ans, tmp)
    
    return ans


if __name__ == "__main__":
    N = int(input())
    
    print(func(N))

Solution (Python):
def main():
    N = int(input())
    loop = int(N ** 0.5)

    ans = float("inf")
    for i in range(1, loop + 1):
        if N % i == 0:
            j = N // i
            tmp = i + j - 2

            if tmp < ans:
                ans = tmp
    print(ans)


if __name__ == "__main__":
    main()

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

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

for i in range(r):
    if N%(r-i)==0:
        l=N/(r-i)
        r=r-i
        break

print("{:}".format(int(r+l-2)))

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

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

Solution (Python):





from collections import deque


def resolve():
    N=int(input())

    minroute=10**15
    for i in range(1,int(N**0.5)+2):
        if N%i==0:
            minroute=min(minroute,i+(N//i)-2)

    print(minroute)




resolve()

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

Solution (Python):
import sys
import math
input = sys.stdin.readline

def main():
    N = int(input())
    if N == 1:
        print(0)
        quit()

    ans = float('INF')
    m = math.ceil(N ** 0.5)
    for a in range(1, m + 1):
        if N % a == 0:
            b = N // a
            ans = min(ans, (a + b - 2))

    print(ans)


if __name__ == "__main__":
    main()

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

i = 1
j = 1 
l = []
while i <= (N/i):
  if N%i == 0:
    j = int(N/i)
    l.append([i,j])
  
  i+=1

res = l.pop()
print(res[0]+ res[1] -2)

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

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

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

Solution (Python):

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

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

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

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

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

print(ans)

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

ans = 10**12+10
for i in range(1, int(N**0.5)+5):
    if N%i==0:
        ans=min(ans, i+N//i-2)
print(ans)

Solution (Python):
import math
import sys

n = int(input())

l = []
if n == 2:
    print(1)
    sys.exit()
else:
    for i in range(2, int(math.sqrt(n) + 1)):
        if n % i == 0:
            for i in range(1, int(math.sqrt(n)) + 1):
                if n % i == 0:
                    j = n // i
                    l.append(i + j)
            print(min(l) - 2)
            sys.exit()
print(n -1)

Solution (Python):
n = int(input())
dv = float('inf')
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

div = make_divisors(n)


l = len(make_divisors(n))

if l % 2 == 0:
    for i in range(l//2):
        if dv > (div[i]-1) + (div[l-i-1]-1):
            dv = (div[i]-1) + (div[l-i-1]-1)
else:
    for i in range((l//2)+1):
        if dv > (div[i]-1) + (div[l-i-1]-1):
            dv = (div[i]-1) + (div[l-i-1]-1)

print(dv)

Solution (Python):
import math

N = int(input())
min_ans = N

for a in range(1, int(N ** 0.5) + 1):
    if N % a != 0:
        continue
    b = N // a
    min_ans = min(min_ans, a + b - 2)

print(int(min_ans))

Solution (Python):
N = int(input())
ans = 10**12
for i in range(1,10**6+1):
  j = N//i
  if i*j == N:
    ans = min(i+j-2,ans)
  if i == 10**6 and ans == 10**12:
    ans = N-1
    break
print(ans)

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

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

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

a = make_divisors(n)

l =len(a)
if l % 2 == 0:
	print(a[l//2-1] + a[l//2] - 2)
else:
	print(a[l//2]*2 - 2)

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

Solution (Python):


import math


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

    min_manhattan = float('inf')
    for x in range(1, math.ceil(math.sqrt(n)) + 1):
        q, mod = divmod(n, x)
        if mod:
            continue

        if x + q < min_manhattan:
            min_manhattan = x + q

    print(min_manhattan - 2)


if __name__ == "__main__":
    submit()

Solution (Python):
import math
n=int(input())
p=math.sqrt(n)
def x(g):
  a=g
  c=0
  while a>=0:
    a-=1
    c+=1
  return c-1

m=x(p)
for i in range(m):
  if n%(m-i)==0:
    print(m-2-i+(n//(m-i)))
    break

Solution (Python):
import math
def is_prime(n):
    for i in reversed(range(1,math.ceil(n**0.5)+1)):
        if n%i == 0:
            print(n//i+i-2)
            exit()
    print(n-1)

N = int(input())
is_prime(N)

Solution (Python):
from math import sqrt

n = int(input())
now = sqrt(n) // 1
while n / now % 1 != 0:
  now -= 1

print(int(now + (n // now) -2))

Solution (Python):
import math
N = int(input())
goal = [0,0]
ans = 10**12
for i in range(1,int(math.sqrt(N))+1):
    if(N%i == 0):
        goal = [i,N//i]
        distance = goal[0]+goal[1]-2
        ans = min(ans,distance)
print(ans)

Solution (Python):
N = int(input())
N2 = N ** (1 / 2)
ans = float('Inf')
for i in range(1, int(N2) + 1):
    if N % i == 0:
        a = i + N // i - 2
        if ans > a:
            ans = a
print(ans)

Solution (Python):
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

def solve():
    N = int(input())
    l = factorize(N)
    ans = 10 ** 12
    for i in range(1, int(N ** 0.5)+1):
        if N % i == 0:
            a = N // i
            ans = min(ans, a+i)
    return ans-2        
print(solve())

Solution (Python):

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

Solution (Python):
N = int(input())
div = []
ans = N - 1
i = 2
while i ** 2 <= N:
    if N % i == 0:
        div.append(i)
    i += 1

for d in div:
    ans = min(ans, d + N // d - 2)

print(ans)

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

Solution (Python):
N = int(input())
N2 = N ** (1 / 2)
ans = float("inf")
for i in range(1, int(N2) + 1):
    if N % i == 0:
        a = i + (N // i) - 2
        if ans > a:
            ans = a
print(ans)

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

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

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

Solution (Python):
n=int(input())
x,y=(1,1)
m=10**12+1
for i in range(1, int(n**0.5)+1):
    x+=1
    if n%x==0: y=n//x
    if n==x*y and m>x+y-2:
        m=x+y-2

if m==10**12+1:
    m=n-1
print(m)

Solution (Python):
N = int(input())
i = int(N**0.5)
while N%i!=0:
  i -= 1
print(i+N//i-2)

Solution (Python):
import math

n = int(input())

ans = 10**12
for i in range(1,math.floor(math.sqrt(n))+1) :
  if n%i != 0 :
    continue
  ans = min(ans,i+n//i-2)

print(ans)

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

Solution (Python):
import math

N = int(input())

answer = N + 1
for a in range(1, math.floor(math.sqrt(N)) + 1):
    if  N % a == 0:
        answer = min(answer, int(a + N / a) - 2)
print(answer)

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

Solution (Python):

"""
Created on Tue Mar 10 21:05:26 2020

@author: Kanaru Sato
"""

import math

n = int(input())
rootn = int(math.sqrt(n))

list = []

for i in range(1, rootn+1):
    if n%i ==0:
        list.append([i,n//i])

dist = list[-1][0]+list[-1][1]-2

print(dist)

Solution (Python):
import math
N = int(input())
ans = 10**12
for i in range(1,10**6+1):
  j = math.ceil(N/(i+1))
  if (1+i)*j == N:
    ans = min(i+j-1,ans)
  if i == 10**6 and ans == 10**12:
    ans = N-1
    break
print(ans)

Solution (Python):
import math

N = int(input())
n = int(math.sqrt(N))

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

print(j - 1 + i - 1)

Solution (Python):
a=int(input())
k=int(a**0.5)
while a%k:k-=1
print(k+(a//k)-2)

Solution (Python):
def yakusu(n):
        result = []
        for i in range(1,int(n**0.5)+1):
                if n % i == 0:
                        result.append(i)
                        if i != n // i:
                                result.append(n//i)
        result.sort()
        return result
yakusu = yakusu(int(input()))
m = len(yakusu)
if m % 2 ==0:
        print(yakusu[m//2-1]+yakusu[m//2+1-1]-2)
else:
        print((yakusu[m//2]-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)
    
    return divisors

lis = make_divisors(n)

a = lis.pop()
b = n//a
ans = a+b-2

print(ans)

Solution (Python):
import math

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

    minimum = 10**12
    for i in range(1,math.floor(N**0.5) + 1):
        if(N % i == 0):
            x = i
            y = N // i

            if(minimum > x+y):
                minimum = x + y

    print(minimum - 2)


if __name__ == "__main__":
    main()

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

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

print(min - 2)

Solution (Python):
N=int(input())
n=int(N**0.5)
l=[]
for i in range(1,n+1):
  ll=[]
  if N%i==0:
    ll.append(i)
    ll.append(int(N/i))
    l.append(ll)
mins=10**12
for j in range(len(l)):
  s=l[j][0]-1+l[j][1]-1
  if s<mins:
    mins=s
print(mins)

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

yaku = make_divisors(N)
if len(yaku) % 2 != 0:
    ans = yaku[-1]*2 - 2
    print(ans)
else:
    ans = yaku[-1] + yaku[-2] -2
    print(ans)

Solution (Python):
N = int(input())
i = 2
ans = N - 1

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

print(ans)

Solution (Python):
from math import sqrt
N = int(input())
ans = 10**18
for i in range(1, int(sqrt(N))+1):
    if N//i==i and N%i==0:
        ans = (i-1)*2
        break
    else:
        if N%i==0:
            
            tmp = ((N//i)-1)+(i-1)
            ans = min(tmp, ans)
print(ans)

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


n = int(input())

divisors = make_divisors(n)
print(min([sum(x)-2 for x in divisors]))

Solution (Python):

N = int(input())

inf = float("inf")
MIN = inf

for i in range(1,10**6+1):
    if N%i == 0:
        MIN = min(MIN,(i-1) + (N//i - 1))

print(MIN)

Solution (Python):
import math
import copy
from copy import deepcopy
import sys
import fractions

from functools import reduce

import heapq
import collections
import itertools
sys.setrecursionlimit(100001)






def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList




n = int(input())

ans = sys.maxsize
for i in range(1, n, 1):
    if i > math.sqrt(n):
        break

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

print(ans)

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

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

Solution (Python):
n=int(input())
l=[]
for i in range(2,int((n**0.5))+1):
  if n%i==0:
    l.append(i)
if len(l)>=1:
  print(max(l)-1+n//max(l)-1)
else:
  print(n-1)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline

    n = int(input())
    n_root = int(n**(1/2)) + 100

    c = 10 ** 18

    for i in range(1,n_root):
        if n % i == 0:
            c_new = (n // i) + i
            c = min(c_new,c)
    
    print(c - 2)



if __name__ == "__main__":
    main()

Solution (Python):
import math as m
n = int(input())
max1 = 0
sqr = m.ceil(m.sqrt(n) + 1)
if n == 1:
	print(0)
	exit()
for i in range(1,sqr):
	if n%i == 0:
		max1 = max(max1, i)
print(max1 + n//max1 - 2)

Solution (Python):
import math

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

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

i = tmp_list[len(tmp_list)-1]
j = n//i

print(i+j-2)

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

Solution (Python):
import math

N = int(input())


for n in reversed(range(1, int(math.sqrt(N)) + 1)):
  if N % n == 0:
    a = int(n + N/n)
    break


print(a - 2)

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

ans = 10**13
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())
number = int(n ** 0.5)+1
ans = 1000000000000

for i in range(1,number):
    if n % i == 0:
        tmp = i + int(n / i) -2
        if tmp < ans:
            ans = tmp

print(ans)

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

ans=10**12
for i in make_divisors(N):
    j=N//i
    if ans>i+j:
        ans=i+j

print(ans-2)

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

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

print(min(t) - 2)

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

Min = 2*(10**12)-2
i=1

while(i<=(N**0.5)):
    j = N/i
    if j.is_integer():
        if (i+j-2)<Min:
            Min=i+j-2
    i+=1
    
print(int(Min))

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

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

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

Solution (Python):
from sys import stdin


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(stdin.readline().rstrip())

d = make_divisors(n)
m = len(d)//2

start = [1, 1]
goal = []

if len(d) % 2 == 0:
    goal = [d[m-1], d[m]]
else:
    goal = [d[m], d[m]]

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

print(ans)

Solution (Python):
import numpy as np

n = int(input())

U = np.arange(1, n ** 0.5 + 1, dtype = np.int64) 

div = U[n % U == 0]
ans = min((n / div) + div) - 2

print(int(ans))

"""old


from itertools import combinations
import numpy as np

n = int(input())

a = 2
cnt = 0
ans = []


def walk_counter(ll, n):
    left = np.prod(ll)
    right = n // left
    return left + right - 2


tmp_n = n

while tmp_n >= a:
    while tmp_n % a == 0:
        tmp_n = tmp_n // a
        
        ans.append(a)
    
    
    
    a = a + 1

if tmp_n == a:
    ans.append(a)

fin = 0

for i in range(len(ans)):
    for v in combinations(ans, i):
        tmp = walk_counter(v, n)
        if i == 0:
            fin = tmp
        elif fin > tmp:
            fin = tmp



print(fin)
"""

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

print(int(a + n/a -2))

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

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

ans = 10**13
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):
import math
import numpy as np

N = int(input())
root_N = int(math.floor(math.sqrt(N))+1)

res = []
for a in range(1, root_N):
  if (N/a).is_integer():
    res.append(a + N/a - 2)

res = np.array(res)
print(int(res.min()))

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

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

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

L = divisors(N)
ans = float('inf')

for l in L:
    tmp = sum(l) - 2
    ans = min(ans,tmp)
print(ans)

Solution (Python):
def main():
    n=int(input())
    for i in range(int(n**.5)+1,0,-1):
        if  not n%i:
            m = n//i
            print(i+m-2)
            return
main()

Solution (Python):
import sys

n=int(sys.stdin.readline())
min=n

for i in range(1,int(n**(1/2))+1):
    if n%i==0:
        c=n//i+i-2
        if c<min:
            min=c
print(min)

Solution (Python):
import math

n = int(input())

ans = 100100100100100
a = 1
while a <= math.sqrt(n):
    if n%a == 0:
        ans = min(ans, int(a + n/a - 2))
    a += 1

print(ans)

Solution (Python):
import math,itertools,fractions,heapq,collections,bisect,sys,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 I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

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


print(main())

Solution (Python):
import sys
import os
import math

def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

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

    max = int(math.sqrt(N) + 1)
    ret = float('inf')
    for i in range(1, max):
        q, mod = divmod(N, i)
        if mod == 0:
            j = N // i
            ret = min(ret, ((j-1)+(i-1)))

    print(ret)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

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

    ret = float('inf')
    for i in range(1, 10000000):
        q, mod = divmod(N, i)
        if mod == 0:
            j = N // i
            ret = min(ret, ((j-1)+(i-1)))

    print(ret)


if __name__ == '__main__':
    main()

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,n//i+i-2)
print(ans)

Solution (Python):
N=int(input())
move=int(N**.5)
while N%move!=0:
    move-=1
print(N//move+move-2)

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

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


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

Solution (Python):
import math


n = int(input())







































ansMax = 1000000000000
num = int(math.sqrt(n))
for i in range(1, num + 1):
    if n % i == 0:
        b = (n // i)
        if i + b - 2 < ansMax:
            ansMax = i + b - 2

print(ansMax)

Solution (Python):
import math
n=int(input())
if n==4:
    print(2)
elif n<=5:
    print(n-1)
else:
    ans=n-1
    for i in range(math.floor(n**0.5),1,-1):
        if n%i==0:
            ans=i+n//i-2
            break
    print(ans)

Solution (Python):
import math

n = int(input())

start = int(math.sqrt(n)+0.5)
l =[]
for i in range(1,start+1):
    if n % i == 0:
        a = i
        b = n // i
        l.append(a+b-2)

print(min(l))

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

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

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())
ls = make_divisors(n)
pairs = []
for i in ls:
    pair = (i, n//i)
    pairs.append(pair)
count = []
for pair in pairs:
    count.append(pair[0] + pair[1] - 2)
print(min(count))

Solution (Python):




def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(n // i)
        i += 1
    table = list(set(table))
    return table


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

    div = divisor(N)

    result = []
    for d in div:
        result.append(N // d + d - 2)
    print(min(result))


if __name__ == "__main__":
    main()

Solution (Python):
import math

num = int(input())
limit = int(math.sqrt(num))

min = num

for i in range(1,limit+1):
  sign = num%i
  if sign == 0:
    temp = (num//i) + i - 2
    if min > temp:
      min = temp 
      
print(min)

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

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

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

list_n = make_divisors(n)

a = len(list_n)
ans = []
for i in range(0, a-1, 2):
    ans.append(list_n[i]+list_n[i+1])

ans.sort()

print(ans[0]-2)

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    ans = inf
    for i in range(1,int(sqrt(N)+1)):
        if N%i==0:
            ans = i+N//i-2

    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
import sys
import fractions


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    m = 1
    for i in range(2, int(n ** 0.5) + 1):
        m = max(m, fractions.gcd(n, i))
    print(n // m + m - 2)


if __name__ == '__main__':
    solve()

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

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

ans=10**12
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 = 10 ** 18

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

print(ans)

Solution (Python):
import math

N = int(input())

ans = 10**13


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

Solution (Python):
import math

N=int(input())
M=int(math.sqrt(N))
ans=float("inf")
for i in range(1,M+1):
	if N%i==0:
		ans=min(ans,N//i+i)
print(ans-2)

Solution (Python):

n = int(input())

tmp = 10 ** 24
tmp2 = 1
tmp3 = 1
for i in range(1, 10 ** 6 + 1):
    if n % i == 0 and i + (n / i) < tmp:
        tmp = i + (n // i)
        tmp2 = i
        tmp3 = n // i
print(tmp2 + tmp3 - 2)

Solution (Python):
import sys

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())
a = make_divisors(n)

ans = sys.maxsize
for x in a:
    y = n // x
    
    ans = min(ans, x + y - 2)
print(ans)

Solution (Python):
import sys
def solve():
    N = int(input())
    moveN = 10000000000000000000
    for i in range(1, N + 1):
        if i ** 2 > N: break
        if N % i == 0:
            moveN = min(i + (N // i) - 2, moveN)
    print(moveN)

    return 0

if __name__ == "__main__":
    solve()