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())
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())
from math import sqrt
for i in range(int(sqrt(N)),0,-1):
    if N % i == 0:
        print(N//i+i-2)
        break

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

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


N = int(input())
divs = make_divisors(N)
if len(divs) % 2 == 0:
    print(divs[len(divs)//2 - 1] + divs[len(divs)//2] - 2)
else:
    print(divs[len(divs)//2] * 2 - 2)

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

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

Solution (Python):
import math
int_n = int(input())
i = (math.sqrt(int_n))
i = math.floor(i)
while i >= 1:
    if int_n % i == 0:
        j = int_n/i
        print(math.floor((i - 1) + (j - 1)))
        break
    i = i - 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);exit()

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

half = int(N**(1/2) + 1)

a=1
b=10**12
for i in range(1,half+1):
    if N%i == 0:
        if abs(a-b) > abs(i - N/i):
            a = i
            b = N//i

print(abs(a-1+b-1))

Solution (Python):
import math
n, = map(int, raw_input().split())
n_s = int(math.sqrt(n))
ans = float('inf')
for i in range(1, n_s+1):
    if n % i == 0:
        j = n//i
        ans = min(ans, (i-1+j-1))

print ans

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

Solution (Python):
from math import sqrt, ceil


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

    pairs = [(i, n // i) for i in range(1, ceil(sqrt(n)) + 1) if n % i == 0]

    least_distance = min(map(lambda x: x[0] + x[1], pairs))

    print(least_distance - 2)


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

ret = int(input())
r=make_divisors(ret)
if(len(r)%2==1):
    print(r[-1]*2-2)
else:
    for i in range(0,int(len(r)/2)):
        if(r[i*2]+r[i*2+1]-2<ret):
            ret=r[i*2]+r[i*2+1]-2
    print(ret)

Solution (Python):
import numpy as np
 
N = int(input())
ans = 10**12
for i in range(int(np.sqrt(N)+0.5)):
  a = i+1
  if N % a != 0:
    continue
  step = a + int(N/a) -2
  if step < ans:
    ans = step
print(ans)

Solution (Python):
import math


class Solution:
    def solve(self, n: int) -> int:

        maxDivisor = int(math.sqrt(n) + 0.5)

        for i in range(1, maxDivisor + 1):
            if n % i == 0:
                p = i

        q = n // p

        return p+q-2


if __name__ == '__main__':

    
    n = int(input())

    
    solution = Solution()
    print(solution.solve(n))

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

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

print(ans)

Solution (Python):
import math
N=int(input())
n=int(math.sqrt(N))
ans=float('inf')
val=0
a=0
b=0
for i in range(1,n+1):
  if N%i==0:
    a=i
    b=N//i
    val=a+b-2
    ans=min(ans,val)
print(ans)

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

distance = 10 ** 12

i = 1

while i * i <= n:
  if n % i == 0:
    m = int(n / i)
    move = (m - 1) + (i - 1)
    if move < distance:
      distance = move
  i += 1

print(distance)

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

Solution (Python):
import math

n=int(input())

base = int(math.ceil(math.sqrt(n)))

while True:
	
	if  n % base == 0:
		a = base
		break
		
	else:
		base -= 1
		
b = n // a

print(a+b-2)

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

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


while n%s != 0:
  s -= 1
s2 = n // s

print(s+s2-2)

Solution (Python):
import random
def p(n):
    r = []
    a, b = 0, 2
    while b * b <= n:
        if n % b == 0:
            n //= b
            r += [b]
        else:
            b += 1 + a
            a = 1
    if n > 1 : r += [n]
    return r
n = int(input())
m = p(n)
ans = n-1
for i in range(2048):
    random.shuffle(m)
    a = 1
    b = n
    for i in m:
        if a >= b : break
        b //= i
        a *= i
    ans = min(ans, a+b-2)
    
print(ans)

Solution (Python):




def I(): return int(input())


def IsIl(): return list(map(lambda x: int(x), input().split()))


def InIl(n): return [input() for i in range(n)]


def IsIt(): return map(lambda x: int(x), input().split())


def InIl(n): return map(input() for i in range(n))


def SsSl(): return list(map(lambda x: x, input()))




def SSd():
    from collections import defaultdict
    A = input() 
    dd=defaultdict(int)
    for a in A:
        dd[a]+=1
    return dd

import math

n=I()

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

Solution (Python):
import math

N = int(input())

def trial_division(target):
  dest = int(math.sqrt(target))

  for i in range(dest, 1, -1):
    if target % i == 0:
      return i
  
  return 1

A = trial_division(N)
B = int(N / A)
print(A + B - 2)

Solution (Python):
from math import sqrt
from sys import exit

N = int(input())

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

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

min_i = 1
min_j = N

for i in range(2, int(N**0.5)+1):
    if N%i==0:
        j = N / i
        
        if i + j < min_i + min_j:
            min_i = i
            min_j = j
            
print(int(min_i+min_j-2))

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

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

for i in range(r_n, 0, -1):
    if not n % i:
        ans = [i, n/i]
        break

print(int(sum(ans)-2))

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

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

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

def make_divisors(n):
    ans =10**12
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            a = i
            b = n//i
            if a+b-2 < ans:
                ans = a+b-2
            
    
    return ans

ans = make_divisors(n)

print(ans)

Solution (Python):
import math

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

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

Solution (Python):



def main():
    import sys
    import math
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

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


if __name__ == '__main__':
    main()

Solution (Python):
import math

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

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

Solution (Python):
import math 

n = int(input())
a=0
b=0
root_n  = math.sqrt(n)

root_n = math.ceil(root_n)
yakusuu =[]
for i in range(1,root_n+1):
    if(n%i == 0):
        yakusuu.append(i)
a = max(yakusuu)
b = n / a
print(int(a+b-2))

Solution (Python):
from sys import stdin
n = int(stdin.readline().rstrip())

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):
from numpy import sqrt

n=int(input())

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

Solution (Python):
from math import sqrt,floor

def main():
    n = int(input())
    rn = floor(sqrt(n))
    movestep = 10**12
    for i in range(1, rn + 1):
        if n % i == 0:
            step = i + int(n / i) - 2
            if movestep > step:
                movestep = step
    print(movestep)


if __name__ == '__main__':
    main()

Solution (Python):
from math import sqrt,floor

def main():
    n = int(input())
    rn = floor(sqrt(n))
    movesteps = set()
    for i in range(1, rn + 1):
        if n % i == 0:
            movesteps.add(i + int(n / i) - 2)
    print(min(movesteps))


if __name__ == '__main__':
    main()

Solution (Python):
import math

n= int(input())
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

res  = []
if is_prime(n):
    res.append(n - 1)
else:
    for t in range(1, int(math.sqrt(n)) + 1):
        if n % t == 0:
                res.append(n//t + t - 2)


print(min(res))

Solution (Python):
import math

n= int(input())
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

i, j = 10**12, 10**12
res  = 0
if is_prime(n):
    res = n - 1
else:
    for t in range(1, int(math.sqrt(n)) + 1):
        if n % t == 0:
            a, b = t, n//t
            if a + b < i + j:
                i, j = a, b
    res = i + j -2


print(res)

Solution (Python):
import math

N = int(input())
n = math.sqrt(N)
ans = 10 ** 12

for i in range(1 , math.ceil(n) + 1):
  if i * (N // i) == N:
    count = (i - 1) + ((N // i) - 1)
    ans = min(ans , count)
    
print(ans)

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

Solution (Python):
N = int(input())
S = []
for k in range(1,N):
    if k**2 <= N:
        if N % k == 0:
            S.append(N/k+k-2)
        else:
            continue
    if k**2 > N:
        break
print(int(min(S)))

Solution (Python):
import math

N = int(input())

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

Solution (Python):
import math
n = int(input())
ans = 9999999999999
for i in range(1, math.ceil(math.sqrt(n+1))):
    x1 = i
    x2 = n // x1
    if x1 * x2 == n and x1 + x2 < ans:
        ans = x1-1 + x2 -1
print(ans)

Solution (Python):
N = int(input())
dc_max = 1
temp = int(N**0.5)
for i in range(1,int(N**0.5)+1):
  if N%i == 0:
    dc_max = i

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

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

Nlist = []

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

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)

print(ans-2)

Solution (Python):
import math

N = int(input())

ans = 1e18
for i in range(int(math.sqrt(N)), 0, -1):
    if N%i != 0:
        continue
    j = N/i
    ans = min(ans, i+j-2)
print(int(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)
    divisors.sort()
    return divisors


r = make_divisors(n)

i = len(r)//2
j = i-1

if len(r) % 2 == 1:
    print(r[i]-1+r[i]-1)
    exit()

print(r[i]-1+r[j]-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)

    
    return divisors

if __name__ == "__main__":
    li = list(map(int,input().split()))
    a=li[0]
    r=[]
    ret=a-1

    r=make_divisors(a)
    if(len(r)%2==1):
        print(r[-1]*2-2)
    else:
        for i in range(0,int(len(r)/2)):
            if(r[i*2]+r[i*2+1]-2<ret):
                ret=r[i*2]+r[i*2+1]-2
        print(ret)

Solution (Python):
import math
def main1():
    input_num = int(input())
    num_sqrt = int(math.sqrt(input_num))

    minimam = input_num
    for i in range(num_sqrt+1,0,-1):
        q, mod = divmod(input_num, i)
        if mod == 0:
            distance = q + i -2
            if minimam > distance:
                minimam = distance
    print(minimam)
main1()

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

minimam = input_num
for i in range(num_sqrt+1,0,-1):
    q, mod = divmod(input_num, i)
    distance = q + i -2
    if mod == 0 and minimam > distance:
        minimam = distance
print(minimam)

Solution (Python):
import math
input_num = int(input())
num_sqrt = int(math.sqrt(input_num))+1

minimam = input_num
for i in range(1,num_sqrt+1):
    q, mod = divmod(input_num, i)
    distance = q + i -2
    if mod == 0 and minimam > distance:
        minimam = distance
print(minimam)

Solution (Python):
num = int(input())
minimam = 10**12
for i in range(1,10**6+1):
    q, mod = divmod(num, i)
    distance = q + i -2
    if mod == 0 and minimam > distance:
        minimam = distance
print(minimam)

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

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

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

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

Solution (Python):
import math
N = int(input())
len = math.floor(N**0.5)
for i in range(len):
    if N%(len-i) == 0:
        j = N//(len-i)
        break
print(int(len-i+j-2))

Solution (Python):

a = int(input())
j=0
mass=1000000000000
for i in range(round(a**(1/2))):
    j = j+1
    h=a/j
    if (h.is_integer()):    
        mass2=j+h-2
        if(mass>mass2):
            mass=mass2
        

    

print(int(mass))

Solution (Python):
import math
n = int(input())
half = math.floor(n**0.5)


num1 = 0
for i in range(half+1,0,-1):
  if n % i == 0:
    num1,num2 = i,n//i  
    
    break

if num1 == 0:
  print(n-1)
else:
  print(num1+num2-2)

Solution (Python):
import math 
 
n = int(input())
m = int(round(math.sqrt(n)))
while m >= 1:
    p, q = divmod(n, m)
    if q == 0:
        print(m + p - 2)
        break
    else:
        m -= 1

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

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


def main():
    sc = Scan()
    n = sc.intarr()[0]
    ns = int(math.sqrt(n)) + 1
    minimum = n
    for i in range(1, ns):
        if n % i == 0:
            cost = (n//i) + i - 2
            if cost < minimum:
                minimum = cost
    print(minimum)


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()

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


def main():
    sc = Scan()
    n = sc.intarr()[0]
    ns = int(math.sqrt(n)) + 1
    minimum = n
    for i in range(1, ns):
        if n % i == 0:
            cost = (n//i) + i - 2
            if cost < minimum:
                minimum = cost
    print(minimum)


class Scan():

    def intarr(self):
        self.line = input()
        array = self.line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        self.line = input()
        array = self.line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()

Solution (Python):
import math

def dictcheck(dict):
    min = 0
    for k,v in dict.items():
        if k == 1:
            min = v
            break
        elif min == 0:
            min=(int(k)-1)+(int(v)-1)
        elif min > (int(k)-1)+(int(v)-1):
            min = (int(k)-1)+(int(v)-1)
        else:
            continue
    print(min)

def main():
    N = int(input())
    i = 2
    tmpdict= {}
    while i <= math.sqrt(N):
        if N % i == 0:
            tmpdata = {i:N/i}
            tmpdict.update(tmpdata)
            i+=1
        else:
            i+=1
    if len(tmpdict)==0:
        tmpdata = {1:N-1}
        tmpdict.update(tmpdata)

    dictcheck(tmpdict)

if __name__ == "__main__":
    main()

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

Solution (Python):
import math
N = int(input())
q = []

for i in range(1,min(N,2+math.ceil(math.sqrt(N)))):
    if N%i==0:
        q.append(i+int(N/i))

print(min(q)-2)

Solution (Python):
import math

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

for i in range(n_sqrt, 0, -1):
    if n % i == 0:
        yoko, tate = i, n//i
        break

print(yoko + tate - 2)

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

Solution (Python):
N = int(input(''))
N_max=int(N**0.5)

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

print(int(A-2))

Solution (Python):
import math

raw = input()
N = int(raw)
n = math.sqrt(N)
a,b = math.modf(n)
m = int(b)

count = N - 1

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

print(count)

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

i=int(N**0.5);

while i>0:
    if N%i==0:
        i,j=(i,N/i)
        break
    i-=1

print(int(i+j-2))

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

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

	
	return divisors
	
print(sum(make_divisors(n)[-1])-2)

Solution (Python):
s = int(input())
min = s - 1
sqr = s ** 0.5
i = int(sqr)
while i >= 1:
    if s % i == 0:
       t = i + (s // i) - 2
       break
    i -= 1
print(t)

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


def main():
    sc = Scan()
    n = sc.intarr()[0]
    ns = int(math.sqrt(n)) + 1
    minimum = n
    for i in range(1, ns):
        if n % i == 0:
            cost = (n//i) + i - 2
            if cost < minimum:
                minimum = cost
    print(minimum)


class Scan():

    def intarr(self):
        self.line = input()
        array = self.line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        self.line = input()
        array = self.line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()

Solution (Python):
import math

N = int(input())




divisor = []
for i in range(1 , math.floor(N**(1/2))+1):
    if N % i == 0:
        divisor.append(i)

distance = []
for j in range(int(len(divisor))):
    M = (N / int(divisor[j])) + int(divisor[j])
    distance.append(M)

if int(len(divisor)) == 1:
    print(N-1)
else:
    print(math.floor(min(distance))-2)

Solution (Python):
import math

N = int(input())

divisor = []
for i in range(1 , math.floor(N**(1/2))+1):
    if N % i == 0:
        divisor.append(i)

distance = []
for j in range(int(len(divisor))):
    M = (N / int(divisor[j])) + int(divisor[j])
    distance.append(M)

if int(len(divisor)) == 1:
    print(N-1)
else:
    print(math.floor(min(distance))-2)

Solution (Python):

import math

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

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

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

x = 1
ans = float('inf')
while x * x <= n:
    if n % x == 0:
        y = n // x
        ans = min(ans, x - 1 + y - 1)
    x += 1
print(ans)

Solution (Python):
from math import sqrt, ceil

n = int(input())
for i in range(ceil(sqrt(n)),0, -1):
    if n%i == 0:

        print(i+(n//i)-2)
        exit()

Solution (Python):
import math
x=int(input())
s=set()
y=int(math.sqrt(x))
for i in range(y,0,-1):
  if x%i == 0:
    a=i+x//i-2
    s.add(a)
    if min(s)-a <0:
      break
print(min(s))

Solution (Python):
from sys import stdin
input = int(stdin.readline().rstrip())

search_area = 1
tf = True
output = (input - 1)
while(tf):
    if (input % search_area) == 0:
        output_temp = int(search_area + (input / search_area) - 2)
        if output > output_temp:
            output = output_temp
    search_area += 1
    if search_area > (input)**(1/2) + 1:
        tf = False

print(output)

Solution (Python):
a=int(input())
c=a+1
for i in range(1,10000000,1):
    if a%i==0:
        b=a/i
        if i+b<=c:
            c=i+b
print(int(c-2))

Solution (Python):
import numpy as np

A = int(input())
A_sq = int(np.sqrt(A))
for i in range(A_sq):
  if A % (A_sq - i) == 0:
    print(int(A_sq - i + A / (A_sq - i) - 2))
    break

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

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

n = int(np.sqrt(N)) 
ans_list = []
for i in range(1, n + 1):
    if N % i == 0:
        k = int(i + (N / i) - 2) 
        ans_list.append(k) 
    else:
        pass

print(min(ans_list))

Solution (Python):
import numpy as np

n = int(input())
count = 0
ans = []
for i in range(2, int(np.sqrt(n+1))+1):
    if n%i ==0:
        ans.append(i)
if len(ans) == 0:
    print(n-1)
else:
    tmp = max(ans)
    print(tmp+(n//tmp)-2)

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

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

Solution (Python):
n = int(input())
qplusmod = 0
i = 1
ans = n+1
for i in range(1,int(n)):

  if n % i == 0:
    q = n / i
    qplusmod = q + i

    if qplusmod < ans:
      ans = int(qplusmod)
  if i > n/i:

    break
print(int(ans - 2))

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

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

r=round(n**0.5)

while n%r>0:
    r=r-1
print(r+int(n/r)-2)

Solution (Python):
import math
b = input()
a = int(b)

sqA = int(math.sqrt(a))

for i in range(10000000):
    d = a / (sqA - i)
    if d.is_integer() == True:
        break


e = d + sqA - i - 2

print(int(e))

Solution (Python):

from math import sqrt

n = int(input())
a = 0

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

print(a)

Solution (Python):

from math import sqrt

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

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

print(min(a))

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

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

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

Solution (Python):






n = int(input())

ans = n

for i in range(1, 2000000):
    if n / i == n // i:
        ans = min(ans, i - 1 + n / i - 1)

print(int(ans))

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

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

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

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

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
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 LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def f(n):
        if n < 4:
            return [1,n]
        res = [1]
        i = 2
        while i*i <= n:
            if n%i == 0:
                res.append(i)
                m = n//i
                if m != i:
                    res.append(m)
            i += 1
        res.append(n)
        return res

    n = I()
    l = f(n)
    ans = float("inf")
    for x in l:
        m = x+n//x-2
        if m < ans:
            ans = m
    print(ans)
    return


if __name__ == "__main__":
    solve()

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
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 LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def f(n):
        if n < 4:
            return [1,n]
        res = [1]
        i = 2
        while i*i <= n:
            if n%i == 0:
                res.append(i)
                m = n//i
                if m != i:
                    res.append(m)
            i += 1
        res.append(n)
        return res

    n = I()
    l = f(n)
    ans = float("inf")
    for x in l:
        m = x+n//x-2
        if m < ans:
            ans = m
    print(ans)
    return


if __name__ == "__main__":
    solve()

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

    return arr

print(min(factorization(N) ))

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

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

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

min = [max(list),input/max(list)]

print(int(min[0]+min[1]-2))

Solution (Python):
from math import sqrt
def main():
    n = int(input().rstrip("\n"))
    
    s = int(sqrt(n))
    for number in range(s, 0, -1):
        if n % number == 0:
            print(number + (n // number) - 2)
            break
    
    
if __name__ == '__main__':
    main()

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

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

a = 1
while a <= N**0.5:
    if N % a == 0:
        a_max = a
    a += 1
print(int(a_max + N / a_max - 2))

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

Solution (Python):
import math
yu = int(input())
result = []
if yu == 2:
	print(1)
	quit()
for i in range(1,round(math.sqrt(yu)+1)):
	if yu % i == 0:
		result.append(i)


print(round(max(result)-1+(yu/max(result))-1))

Solution (Python):


N = int(input())

chk = 0

for i in range(1, int(N ** 0.5) + 1):
    if N % i == 0:
        cp = N / i
        temp = i + cp

        if chk != 0:
            if temp < chk:
                chk = temp
        else:
            chk = temp

print(int(chk - 2))

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

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

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

Solution (Python):
import sys
N = int(sys.stdin.readline())

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

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

    result_list = [int(x + n/x -2) for x in divisors]
    
    return min(result_list)

input_data = int(input())

print(minimumMove(input_data))