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())
i = 2
ans = n - 1
while i < n:
  if i * i > n:
    i += 1
    break
  if n % i > 0:
    i += 1
    continue
  j = n // i
  ans = min(ans, i + j - 2)
  i += 1
print(ans)

Solution (Python):

import math

MOD = 10 ** 9 + 7
n = int(input())

ans = 10**13
for x in range(1, int(math.sqrt(n)) + 1):
    if n % x == 0:
        y = n // x
        ans = min(ans, x + y - 2)
print(ans)

Solution (Python):
N=int(input())
D=[]
i=1
while(i*i<=N):
    if N%i==0:
        D.append(i)
        D.append(N//i)
    i+=1
ans=N-1
for i in D:
    j=N//i
    ans=min(ans,i+j-2)
print(ans)

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

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

p = 1

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

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

Solution (Python):
from math import sqrt, ceil


def square_like_factors(n):
  root_n = ceil(sqrt(n))
  for i in reversed(range(1, 1 + root_n)):
    if n % i == 0:
      return (i, n // i)
  return (1, n)


n = int(input())
a, b = square_like_factors(n)
print(a + b - 2)

Solution (Python):
import sys
n=int(input())
L=[]
for i in range(1,int(n**(1/2))+1):
    if n//i == n/i:
        L.append(n//i+i-2)
print(min(L))

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

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

Solution (Python):

n = (int)(input())

minimum = 1e18
i = 1
while(i*i <= n):
    if n % i != 0:
        i += 1
        continue;
    j = (int) (n / i)
    minimum = min(i + j - 2, minimum)
    i +=1

print(minimum)

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

q1 = 1
q2 = N

step = q1 + q2 - 2

for i in range(N):
    x = i+1
    if x**2 > N:
        break
    if N % x == 0:
        q1_cand = x
        q2_cand = N / x
        step_cand = q1_cand + q2_cand - 2
        if step_cand < step:
            step = step_cand
print(str(int(step)))

Solution (Python):
from heapq import heapify, heappush, heappop
N = int(input())
heap = []
heapify(heap)
for i in range(1, int(N**(0.5)) + 1):
    if N % i == 0:
        heappush(heap, i - 1 + N // i - 1)
print(heappop(heap))

Solution (Python):
a = int(input())
i = 1
otv = 10**20
while i*i <= a:
    if a%i == 0:
        otv = min(otv, a//i + i - 2) 
    i += 1
print(otv)

Solution (Python):
from heapq import heappush, heappop
from collections import deque
import re
import math
import functools

def sRaw():
    return input().rstrip("\r")

def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29


def make1d_arr(n, val=INF):
    return [val for i in range(n)]


def make2d_arr(h, w, val=INF):
    return [[val for i in range(w)]for i in range(h)]


def gcd(a, b):
    if(b == 0):
        return a
    return gcd(b, a % b)


def BFord(n,es):
    v_cost = [INF]*n
    v_cost[0] = 0
    for v in range(n*2):
        for e in es:
            frm = e[0]
            to = e[1]
            if v_cost[to] > v_cost[frm]+e[2]:
                v_cost[to] = v_cost[frm]+e[2]
                if v >= n:
                    v_cost[to] = -INF
        if v == n-1:
            prev = v_cost[:]
    v_cost = [-INF if prev[idx]!=v_cost[idx] else v_cost[idx] for idx in range(n)]
    return v_cost
    
def ZAlgo(s):
    l = len(s)
    A = [0]*l
    i =1
    j =0
    A[0]=l
    while i<l:
        while i+j<l and s[j] == s[i+j]:
            j+=1
        if j==0:
            i+=1
            continue
        A[i]=j
        k=1
        while (i+k<l) and (k+A[k]<j):
            A[i+k] =A[k]
            k+=1
        i+=k
        j-=k
    return A


def main():
    N = iRaw()
    i = 1
    ans = N
    while i*i <= N:
        if N%i ==0:
            j = N//i
            ans = min(ans,i-1+j-1)
        i+=1
    return ans

if __name__ == "__main__":
    print(main())

Solution (Python):
import math
ans = 10 ** 15

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

print(ans)

Solution (Python):


import math
N = int(input())
tmpn = math.ceil(math.sqrt(N))

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

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

b=n
a=[]
N=int(math.sqrt(n))

for i in range(1,N+1):
 q, mod=divmod(n,i)
 a=q+i-2

 if(mod==0 and a<b):
     b=a

print(b)

Solution (Python):
import math

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

for i in range(m,0,-1):
    (j, mod) = divmod(n, i)
    if mod == 0:
        print(i+j-2)
        break

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

Solution (Python):
N = int(input())
a = 1
b = N
min = a + b - 2
while a <= N**(1/2):
    b = N // a
    if N % a == 0 and a + b - 2 < min:
        min = a + b - 2    
    a = a + 1
print(min)

Solution (Python):
import math

n = int(input())
ans=n

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

Solution (Python):
import math
N = int(input())
ans = 10**12
root = int(math.sqrt(N))+1
for i in range(1,root):
    if N % i == 0:
        ans = min(ans,(i-1)+(N//i-1))
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)
            if i != n // i:
                divisors.append(n//i)

    return divisors
a = int(input())
b = make_divisors(a)
c = len(b)/2
d = len(b)-1
if c.is_integer()==False:
  print(b[d]*2-2)
else:
  print(b[d]+b[d-1]-2)

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

pair = [n, 1]
i = 2
d_min = n**2 + 1
while i * i <= n:
    if n % i == 0 and d_min > (n/i)**2 + i**2:
        pair[0] = int(n/i)
        pair[1] = i
    i += 1

print(pair[0]+pair[1]-2)

Solution (Python):
import math
n = int(input())
n2 = int(math.sqrt(n))

minimum=n-1
for i in range(2,n2+1):
  if(n%i==0):
    minimum=min(minimum,(n//i-1)+(i-1))

print(int(minimum))

Solution (Python):
from math import sqrt, ceil

N = int(input())



n,m = 0,0
for i in reversed(range(1, ceil(sqrt(N))+1 )):
  if N % i == 0:
    n = i
    m = int(N / i)
    break

print(n-1+m-1)

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
a = int(input())
ar = make_divisors(a)
br = []
for r in ar:
    br.append((r - 1) +  ((a // r) - 1))
print(min(br))

Solution (Python):
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

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

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

def get_divisors(n):
    """
    n の約数をリストで返す
    :param int n:
    :rtype: list of int
    """
    ret = []
    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0:
            ret.append(i)
            if n // i != i:
                ret.append(n // i)
    return ret


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

divs = get_divisors(N)
ans = INF
for d in divs:
    a = N // d
    b = d
    ans = min(ans, a + b)
print(ans - 2)

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

Solution (Python):
n = int(input())
list=[]
for i in range(1,int(n**0.5+1)):
  if n%i == 0:
    list.append(int(i+n/i))
print(min(list)-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

divisors_lst = make_divisors(n)

mins = 10**100
for i in divisors_lst:
    j = n // i
    if i + j < mins:
        ans = i + j
        mins = i * j

print(ans-2)

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

Solution (Python):
from math import sqrt
from math import floor
n = int(input())
for i in range(floor(sqrt(n)), 1, -1):
    if n % i == 0:
        min_div = i
        break
else:
    min_div = n
ans = min_div + int(n / min_div) - 2
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


list = make_divisors(n)
min = 1e13
for i in list:
    if n//i+i < min:
        min = n//i+i

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)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

divs = make_divisors(N)
m_div = divs[(len(divs)+1)//2-1]
M_div = divs[-((len(divs)+1)//2)]

print(m_div+M_div-2)

Solution (Python):
import math
min_steps = 1e18
number = int(input())
a = math.sqrt(number)
for k in range (1,int(a)+1):
    if number%k == 0:
        i = number//k
        steps = k + i - 2
        if steps <= min_steps:
            min_steps = steps
print(min_steps)

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

Solution (Python):
import math

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

ans=1000000000000

for i in range(1,n+1):
    if N%i==0:
        if ans>i+(N/i):
            ans=i+(N/i)

print(int(ans-2))

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

Solution (Python):
import math
input_num = int(input())
sqrt_num = math.floor(math.sqrt(input_num))

min_count = 1 + input_num
for i in range(sqrt_num + 1, 1, -1):
  if(input_num % i == 0) and (min_count > input_num//i + i):
    min_count = input_num//i + i
print(min_count - 2)

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

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

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

print(ans)

Solution (Python):
import math
a = int(input())
x = int(math.sqrt(a))
i = 0
while True:
    b = x - i
    if (a % b) == 0:
        print(int(b + (a/b) - 2))
        break
    i += 1

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

Solution (Python):
import numpy as np
n = int(input())
maxi = int(np.sqrt(n))
ans = 10**15
for a in range(1, maxi+1):
    if n % a ==0:
        b = int(n / a)
        if a+b -2 < ans:
            ans = a + b - 2
print(ans)

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

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

Solution (Python):

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

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

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

x = divisor[-1]
y = N // x

print(x + y - 2)

Solution (Python):
import math

n = int(input())

res = 0
r = int(math.floor(math.sqrt(n)))
for i in reversed(range(1, r + 1)):
  if n % i == 0:
    j = n // i
    res = i + j - 2
    break

print(res)

Solution (Python):
import math
def solve():
    N = int(input())
    rootN = math.sqrt(N)

    min_val = float('inf')
    for a in range(1, math.floor(rootN) + 1):
        if N % a == 0:
            b = N / a
            min_val = min(min_val, a + b - 2)
    
    print(int(min_val))

if __name__ == '__main__':
    solve()

Solution (Python):
n=int(input())
ans=float("inf")
for i in range(1,10**6+1):
    q,m=divmod(n,i)
    if m==0:
        ans=min(ans,q+i-2)
ans=min(ans,1+n)
print(ans)

Solution (Python):

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

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

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

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())
list = make_divisors(N)

if len(list)%2 == 0:
    a,b = list[-2],list[-1]
    print(a+b-2)
else:
    a = list[-1]
    print(2*a-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())


num_lists = make_divisors(N)
ans = 10**12
for num in num_lists:
  x = N//num
  y = num
  ans = min(x-1+y-1,ans)

print(ans)

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

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

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

Solution (Python):


'''
------------------------
author : iiou16
time : 11/01/12:15
------------------------
'''


def main():
    N = int(input())
    org = N
    i = 2
    table = []
    while i * i <= N:
        if N % i == 0:
            j = org / i
            table.append(i + j - 2)
        i += 1
    table.append(org - 1)
    print(int(min(table)))


if __name__ == '__main__':
    main()

Solution (Python):
import math
import numpy as np

N = int(input())

ans = 2*N
upper = math.ceil(np.sqrt(N))

for i in range(1,upper+1):
    if N%i == 0:
        j = N//i
        ans = min(ans,i+j-2)

print(ans)

Solution (Python):
import math

n = int(input())
a = math.ceil(math.sqrt(n))
min_ans = float('inf')

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

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

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

Solution (Python):
import math
ans =float("inf")
n=int(input())
m=int(math.sqrt(n))+1
for i in range(m):
    if i==0:
        continue
    if n%i==0:
        ans=min(ans,i-1+(n/i)-1)
print(int(ans))

Solution (Python):
import math
import sys

N = int(input())

a = sys.maxsize

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

print(a)

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


ans = n - 1

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())
i = int(n**0.5)
while True:
    if n%i == 0:
        print(i + n//i - 2)
        break
    i -= 1

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

Solution (Python):
import math

def main():
    n = int(input())
    r = math.ceil(math.sqrt(n))
    ans = 0

    for i in range(1, r+1)[::-1]:
        if n % i == 0:
            w = i
            h = n / w
            ans = int(w) + int(h) -2
            break

    print(ans)

if __name__ == '__main__':
    main()

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

a=int(input())

lst=[]
for i in div_make(a):
    lst.append(i[0]+i[1])
ans=0
ans=min(lst)-2
print(ans)

Solution (Python):
import math
N=int(input())
def f(N):
  minn=10000000000000
  k=int(math.sqrt(N)+1)
  for i in range(1,k):
    j=N//i
    if i*j==N :
      minn=min(minn,i-1+j-1)
  return(minn)
print(f(N))

Solution (Python):


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

    
    ans = float("inf")
    for i in range(1, N):
        if i > N**(1/2):
            break

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


if __name__ == "__main__":
    solve()

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))
print(min(li) - 2)

Solution (Python):
n = int(input())
S = []
ans = float('inf')
flag = False
for i in range(2,1000001):
  if n%i == 0:
    S.append([i,n//i])
    flag = True
if flag:
  for i in range(len(S)):
    if S[i][0]+S[i][1]-2 < ans:
      ans = S[i][0]+S[i][1]-2
else:
  ans = n-1
print(ans)

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

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

ress = []

for i in range(1, int(N**0.5)+1):
    if N % i == 0:
        ress.append(i+N//i)

print(min(ress)-2)

Solution (Python):
N = int(input())
n = round(N ** (1/2))
i = n
m = 0
while m == 0:
    if N%i == 0:
        m = N/i
    else:
        i -=1
print(round(i+m-2))

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

for i in range(1,int(a**0.5)+1):
  b = a /i
  if b.is_integer():
    ans.append(int(b+i))

print(min(ans) - 2)

Solution (Python):
import math
n = int(input())
ans = float('inf')
for i in range(1,10**6 + 1)[::-1]:
    if n%i == 0:
        ans = min(ans,i + n//i - 2)

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)
            if i != n // i:
                divisors.append(n//i)

    return divisors


n = int(input())
a = make_divisors(n)
b = []

if len(a) % 2 == 0:
    for i in range(0,len(a),2):
        sum = a[i] + a[i+1]
        b.append(sum)
else:
    b.append(a[len(a)-1]*2)
    for i in range(0,len(a)-1,2):
        sum = a[i] + a[i+1]
        b.append(sum)

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

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

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

Solution (Python):

import numpy as np

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

i = 1
while i*i <= n:
    q, m = divmod(n, i)
    if m == 0:
        ans = min(ans, i+q-2)
    i += 1

print(ans)

Solution (Python):
import sys


def solve():
    sys.setrecursionlimit(2000)
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    mt = 10 ** 20
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            mt = min(mt, i + (n // i) - 2)
    print(mt)


if __name__ == '__main__':
    solve()

Solution (Python):
def solve(num):
  n = int(num)
  for i in range(int(n**0.5)+1, 0, -1):
    if n%i:
      continue
    else:
      j = n/i
      sum = i+j-2
      return(int(sum))
      
      
if __name__ == "__main__":
  print(solve(input()))

Solution (Python):
def solve(string):
    n = int(string)
    for i in range(int(n**0.5), 0, -1):
        if not n % i:
            return str(i + n // i - 2)


if __name__ == '__main__':
    print(solve(input()))

Solution (Python):
def solve(string):
    n = int(string)
    for i in range(int(n**0.5) + 1, 0, -1):
        if not n % i:
            return str(i + n // i - 2)


if __name__ == '__main__':
    print(solve(input()))

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


if __name__ == '__main__':
    print(solve(input()))

Solution (Python):
def solve(string):
    n = int(string)
    for i in range(int(n**0.5) + 1, 0, -1):
        if n % i:
            continue
        else:
            return str(i + n // i - 2)


if __name__ == '__main__':
    print(solve(input()))

Solution (Python):
import math 

N=int(input())

li=[]
l=0
m=0

for i in range(math.floor(math.sqrt(N))):
  if N%(i+1)==0:
    l=i
    m=N/(i+1)-1
    li.append(l+m)
  else:
    pass

print(int(min(li)))

Solution (Python):
def solve(string):
    n = int(string)
    l = int(n**0.5)
    while n % l > 0:
        l -= 1
    return str(l + n // l - 2)


if __name__ == '__main__':
    print(solve(input()))

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

for i in range(int(n**.5), 0, -1):
    if n%i:
        pass
    else:
        print(i + n//i - 2)
        break

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

for i in range(int(N**.5), 0, -1):
    if(N%i):
        pass
    else:
        print(i + N//i - 2)
        break

Solution (Python):
import  math

n = int(input())

ans = n-1

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

print(ans)

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

i=1
List=[]
while i<n**.5+1:
    if n/i==n//i:
        List.append(n//i)
    i=i+1
print(List[-1]+n//List[-1]-2)

Solution (Python):
import math
n = int(input())
m = int(math.sqrt(n)) + 1

ans = n - 1

for a in range(2, m):
  if n % a == 0:
    ans = min(ans, a + n//a - 2)
    
print(ans)

Solution (Python):

import math

if __name__ == '__main__':
    N = int(input())
    mem = 1000000000000000000000000000000000000

    for i in range(1, int(math.sqrt(N)) + 1):
        if N % i == 0 and mem > (i + (N/i) - 2):
            mem = (i + (N/i) - 2)

    print(int(mem))

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

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

import math
sq = math.sqrt(n)
a = math.floor(sq)

for i in reversed(range(1,a+1)):
    if n%i==0:
        a = i
        b = n/i
        print(int(a+b-2))
        exit()

print(n-1)

Solution (Python):
from math import sqrt, floor

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

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

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

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

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

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

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

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

Solution (Python):
import math

N = int(input())

sn = int(math.sqrt(N) // 1)
ans = N

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

print(ans)

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

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

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

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

Solution (Python):
import math


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


if(__name__ == "__main__"):
    main()

Solution (Python):
import numpy as np

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

    INF = 10**6 + 100

    x = np.arange(1,INF,dtype=np.int64)
    div = x[N % x == 0]
    
    
    
    ans = (div + N//div).min() - 2
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import math
a=int(input())
a_max=math.ceil(math.sqrt(a))
ans_1=1
for i in range(a_max):
  x=i+1
  if a%x==0 :
    ans_1=x
ans_2=a/ans_1
ans=int(ans_1+ans_2-2)
print(ans)

Solution (Python):
import math

n = int(input())

ans = n-1

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

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

    
    return divisors
  
N = int(input())
conv_list = make_divisors(N)
ans_taple = conv_list[-1]
print(sum(ans_taple) -2)
print()

Solution (Python):
import sys
 
input = sys.stdin.readline()
N = int(input)
sum = N
if N % 2 == 0:
  halfN = N/2
else:
  halfN = N+1/2
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)
for x in divisors:
  if N%x==0 and (N/x+x-2)<N:
    sum = N/x + x - 2
print(int(sum))

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

Solution (Python):

def main():
    s = int(input())
    root = int(pow(s,0.5))
    temp = 0
    for i in reversed(range(1,root+1)):
        if s%i == 0:
            temp = i
            break
    ans = temp - 1 + (s//temp) - 1

    print(ans)






if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
f=0
moves=9999999999999999999999999999
for i in range(1,int(n**0.5)+1):
    if n%i==0:
        x=i
        y=n//i
        moves=min(moves,(abs(x-1)+abs(y-1)))
print(moves)

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

for i in range(n):
  i = n-i
  if N%i==0:
    print(N//i + 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

l = make_divisors(n)
ans = n
for i in range(len(l)):
  ans = min(ans,(l[i] + n // l[i]) - 2)
print(ans)

Solution (Python):
import math
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())


N=II()
res=INTMAX
for i in range(1, math.floor(math.sqrt(N))+1):
    if N % i == 0:
        res = min(res, i + (N // i) - 2)
print(res)

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

Solution (Python):
import math

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

Solution (Python):
import math

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

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

mi = 10**100

for a in range(1,int(math.sqrt(n))+1,1):
    if (n % a==0):
        b = n//a
        if (mi>a+b-2):
            mi = a+b-2

print(mi)

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

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

Solution (Python):
import math

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

Solution (Python):
import math
n = int(input())
m = int(math.sqrt(n))
while n % m != 0:
  m -= 1
print(n//m + m -2)

Solution (Python):
from math import floor,sqrt 
num = int(input())

min_divisor=floor(sqrt(num))

for i in range(min_divisor,0,-1):
    if num%i ==0:
        min_step= i +(num/i)-2
        break
    

print(int(min_step))

Solution (Python):
import copy
import heapq
import math
import fractions

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def ipmultiplerow(n):
    a = []
    for i in range(n):
        a.append(ip())
    return a
def printmultiplerow(a):
    for i in a:
        print(i)
def printrow(a):
    for i in range(len(a)-1):
        print(a[i],end = " ")
    print(a[-1])


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

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

ans = None
for a in range(1, int(N**0.5) + 1):
    b = N / a
    if float.is_integer(b):
        dist = a + b - 2
        if ans is None or dist < ans:
            ans = int(dist)

print(ans)

Solution (Python):
N = int(input())
N2 = int((N ** (1/2)) //1)


ans = 10 ** 13
for i in range(1, N2 + 1):
  if N % i == 0:
    ans = min(ans, i + N // i - 2)

print(ans)

Solution (Python):
import math

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

m = 10**12
for a in range(1, limit+1):
    b = n // a
    if a*b == n and a+b-2 < m:
        m = a+b-2

print(m)