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):
from math import floor
from math import sqrt
n=int(input())
nn=floor(sqrt(n))
rest=n%nn
while rest!=0:
    nn-=1
    rest=n%nn
nnn=n/nn
print(int(nn+nnn-2))

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

Solution (Python):
import numpy as np
N = int(input())
Abs = int(np.sqrt(N))
if Abs ** 2 == N:
    print(Abs + Abs - 2)
else:
    min = N + 1
    min_i = 1
    for i in range(1, Abs + 1):
        tmp = N // i
        if tmp * i == N:
            if min > tmp:
                min = tmp
                min_i = i
    print(min + min_i - 2)

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

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

print(int(min(ans)))

Solution (Python):
from math import sqrt, ceil

N = int(input())
sq = ceil(sqrt(N))
min_st = N-1

for i in range(2, sq+1):
    if ((N % i) == 0):        
        if (i + N//i - 2 < min_st):
            min_st = i + N//i-2

print(min_st)

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

    i = 1
    ans = 10 ** 18

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

    print(int(ans))


if __name__ == '__main__':
    main()

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

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

X = int(np.sqrt(N))

if X * X < N:
  X = X + 1

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

Solution (Python):
import math
N = int(input())
n = math.floor(N**(1/2))
r = []
for i in range(1,n+1):
    if(N%i == 0):
        r.append(i + N//i)

print(min(r)-2)

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

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

print(a-2)

Solution (Python):
N = int(input())
x = N
y = N
ansx = N
ansy = N
ans = []
n = int(N**0.5)
if N**0.5 == int(N**0.5):
    print(int(N**0.5)*2-2)
else:
    for i in range(n+1):
        if N%(i+1) == 0:
            ans.append(i+1)
    ans.append(N)
    if(ans[1]==N):
        print(N-1)
    else:
        for i in range(len(ans)):
            if ansx+ansy>ans[i] + int(N//ans[i]):
                ansx = ans[i]
                ansy =int(N//ans[i])
        print(ansx + ansy -2)

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 out(N, table):
    r = 0
    for i in table:
        a = i
        b = N / i
        if r > (a-1)+(b-1) or r == 0:
            r = (a-1)+(b-1)
    return int(r)


N = int(input())
table = divisor(N)
r = out(N, table)
print(r)

Solution (Python):
N = int(input())
root_N = int(N**0.5)
def table():
    for i in range(root_N,0,-1):
        if N%i==0:
            return i
a = table()
b = N//a
print(a+b-2)

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

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

Solution (Python):
N = float(input())
import numpy as np
d = 1
for i in range(2,int(np.floor(N**0.5))+1):
	if N%i==0:
		d = i
print(int(d+N/d-2))

Solution (Python):


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

Solution (Python):
def solve(n: int) -> int:
  for i in reversed(range(1, int(n**(1/2)) + 1)):
    if n % i == 0:
      j = n // i
      return i + j - 2
  assert(False)


n = int(input().strip())
print(solve(n))

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

Solution (Python):
import math as m

N = int(input())
ans = [1, N]
for i in range(1, m.ceil(m.sqrt(N)) + 1):
    if N % i == 0 and N // i - i < (ans[1] - ans[0]):
        ans = [i, N // i]
print(sum(ans) - 2)

Solution (Python):
N=int(input())
import sys
import math
ANS = sys.maxsize
i_max = math.ceil(N ** 0.5)

for i in range(1, i_max + 1):
  if N % i != 0:
    continue
  j = N // i
  ANS = min(i+j-2, ANS)


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

dist_list = []

for dj in make_divisors(N):
    if N % dj != 0:
        continue
    di = N / dj
    dist_list.append(
        [int(dj + di - 2), [di, dj]]
    )

dist_list.sort(key=lambda x: x[0])
print(dist_list[0][0])

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

Solution (Python):
data = list(map(int,input().split()))
N = data[0]
i = 1
b = 0
c = float('inf')
while (N / i >= i):
  a = N / i
  b = N % i
  if b == 0:
    r1 = int(i)
    r2 = int(a)
    if (r1 + r2) < c:
      c = int(r1 + r2)
  i = i + 1
print(c-2)

Solution (Python):
N = int(input())
result = int(10e13)

for i in range(1,int(pow(N,0.5)+1)):
    if N%i!=0: continue
    else: result = min(N//i+i,result)
print(result-2)

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

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    a, b = LI()
    def c(x):
        return 1 <= x <= 9
    if c(a) and c(b):
        print(a * b)
        return
    print(0)
    return


def B():
    a = set()
    for i in range(10):
        for K in range(10):
            a.add(i * k)
    x = II()
    if x in a:
        print("Yes")
    else:
        print("No")
    return


def C():
    n = II()
    factlize = []
    ans = inf
    for i in range(1, int(sqrt(n)) + 1):
        if n % i == 0:
            ans = min(ans, n // i + i - 2)
    print(ans)

    return


def D():
    return


def E():
    def solve(m):
        a1 = a[::-1]
        f1 = f[::1]
        res = 0
        for i in range(n):
            if a1[i] * f1[i] <= m:
                continue
            k = m // f1[i]
            res += a1[i] - k
            if res > K:
                return False
        return True

    n, K = LI()
    a = LI()
    a.sort()
    f = LI()
    f.sort()
    ok = max(a) * max(f)
    ng = -1
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if solve(mid):
            ok = mid
        else:
            ng = mid
    print(ok)
    return


def F():
    return



if __name__ == '__main__':
    C()

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

Solution (Python):
import math
n = int(input())
sq_n = int(math.sqrt(n))
s_lis = []
e_lis = []
for i in range(1, sq_n + 1):
    if n % i == 0:
        s_lis.append(i)
        e_lis.append(n // i)
min_len = n + 1 - 2
for s, e in zip(s_lis, e_lis):
    min_len = min(min_len, s + e - 2)
print(min_len)

Solution (Python):
import math


def walk_on_multiplication_table(n: int) -> int:
    minimum = None
    for i in range(1, int(math.sqrt(n)) + 1):
        tmp = int(n % i)
        if tmp == 0:
            r = i + int(n / i) - 2
            if minimum is None:
                minimum = r
            else:
                minimum = min(minimum, r)
    return minimum

if __name__ == '__main__':
    N = int(input())
    result = walk_on_multiplication_table(N)
    print(result)

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

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

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

N_list = make_divisors(N)
if len(N_list) % 2 == 1:
    odd = len(N_list) / 2 
    i = N_list[int(odd)]
    ans = (i - 1)*2
else:
    even = len(N_list) / 2
    i = N_list[int(even) - 1]
    j = N_list[int(even)]
    ans = i+j-2

print(ans)

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

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

print(ans)

Solution (Python):
import math
import sys

n = int(input())

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

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

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

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

print(i + n // i - 2)

Solution (Python):

import sys
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict
def primefactor(n):
     ans=defaultdict(int)
     for i in range(2,int(n**0.5+1)):
         while n%i==0:
             ans[i] += 1
             n //= i
     if n>1:
         ans[n]=1
     return dict(ans)

from itertools import product
from functools import reduce

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

    ans = N - 1
    for v in product(*[range(i+1) for i in d.values()]):
        a = reduce(lambda x, y: x*y, [x**y for x, y in zip(d.keys(), v)])
        b = N // a
        ans = min(a-1 + b-1, ans)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

import sys
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict
def primefactor(n):
     ans=defaultdict(int)
     for i in range(2,int(n**0.5+1)):
         while n%i==0:
             ans[i] += 1
             n //= i
     if n>1:
         ans[n]=1
     return dict(ans)

from itertools import product
from functools import reduce

def main():
    N=int(input())
    d=primefactor(N)
    f=list(d.keys())
    v=[list(range(i+1)) for i in d.values()]
    ans = N - 1
    for i in product(*v):
        a = reduce(lambda x, y: x*y, [x**y for x, y in zip(f, i)])
        b = N // a
        ans = min(a-1 + b-1, ans)

    print(ans)


if __name__ == '__main__':
    main()

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

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

div = 1
ans = 10 ** 12

while n >= div ** 2:
    if n % div == 0:
        ans = n // div + div - 2
    div += 1

print(ans)

Solution (Python):
import math
def get(n):
    a=math.sqrt(n)
    
    i,j=int(a),int(a)
    if a%1==0:
        return 2*a-2
    z=True
    while i>=1 and z:
        if n%i==0:
            z=False
        else:
            i-=1
    
    z=True
    k=n//i
    return int(k-1+i-1)
n=int(input())
print(int(get(n)))

Solution (Python):
import math

N = int(input())

n = math.floor(math.sqrt(N)) + 1
lens = [N-1]
for a in range(2, n):
  if N % a == 0:
    lens.append(a+N//a-2)

print(min(lens))

Solution (Python):
import math

N = int(input())

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

print(min(lens))

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

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

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

def find_divisors(N):
    divisors = []
    for A in range(1, int(N**0.5) + 1):
        if N % A == 0:
            divisors.append(A)



    divisors.sort()
    return divisors

divisors_of_N = find_divisors(N)


num_steps = N+1
for A in divisors_of_N:
    B = N//A
    num_steps = min(num_steps, A+B)

print(num_steps - 2)

Solution (Python):

import math

N = int(input())

sum_min = 10**12+1
ab = None

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

print(sum_min)

Solution (Python):

import math

N = int(input())

res = 10**12+1

if N==1:
    print(0)
else:
    for a in range(1, int(math.sqrt(N))+1):
        if (N%a)==0:
            b = int(N/a)
            if res>a+b-2:
                res = a+b-2
    
    if res == 10**12+1:
        print(N-1)
    else:
        print(res)

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

import numpy as np

N = int(readline())

U = 10**6 + 100

div = np.arange(1, U, dtype=np.int64)
div = div[N%div==0]

div = np.union1d(div, N//div)

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

Solution (Python):
import math
n = int(input())
l = [0]

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

print(l[0]+(n//l[0])-2)

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

for i  in range(1, int(N**(1/2))+1):
    if N % i == 0:
        List_ans.append(i)
        
x = max(List_ans)
y = N//x

Ans = (x-1) + (y-1)
print(Ans)

Solution (Python):
import math

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

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

print(minimum)

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

Solution (Python):
def factorization(n):
  primen = []
  degree = []
  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
      primen.append(i)
      degree.append(cnt)
  if temp!=1:
    primen.append(temp)
    degree.append(1)
  if primen==[]:
    primen.append(n)
    degree.append(1)
  return primen,degree

N = int(input())
ans = factorization(N)
import itertools
T = []
for i in ans[1]:
  T.append(list(range(i+1)))
L = list(itertools.product(*T))
RR = N
for i in L:
  x = 1
  for j in range(len(ans[0])):
    x = x * (ans[0][j]**i[j])
  y = N // x
  R = x - 1 + y - 1
  RR = min(RR,R)
print(RR)

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

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

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

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)

times = 10**12

for j in range(len(divisors)):
    x = divisors[j]
    y = n // x
    time = (x -1) + (y - 1)
    if time < times:
      times = time
print(times)

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

for n in range(sqn):
    sqt = sqn-n
    div = N/sqt
    if div%1 == 0:
        ans = sqt+N/sqt-2
        intans = int(ans)
        print(intans)
        exit()
    else:
        pass

Solution (Python):
import math
n=int(input())
a=math.ceil(math.sqrt(n))
b=max([i for i in range(1,a+1) if n%i==0])
print(b+n//b-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

L=make_divisors(n)

s=float('inf')
for i in L:
      s=min(s,i+(n//i))

print(s-2)

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

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

Solution (Python):


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

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

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

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

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

Solution (Python):
def g(N):
 d=[]
 for i in range(1,int(N**0.5)+1):
  if N%i==0:
   d.append(i)
   d.append(N//i)
 return sorted(d)
d=g(int(input()))
n,m=d[len(d)//2-1:len(d)//2+1]
print(n+m-2)

Solution (Python):
def get_divisors(N):
  divisors = []
  for i in range(1,int(N**0.5)+1):
    if N%i == 0:
      divisors.append(i)
      divisors.append(N//i)
      
  divisors.sort()
  return divisors

divisors = get_divisors(int(input()))
n1,n2 = divisors[len(divisors)//2-1:len(divisors)//2+1]
print(n1+n2-2)

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

ub = int(ceil(sqrt(n)))

factors = []
for i in range(1,ub+1):
        if n % i == 0:
                factors.append(i)
                if n//i != i:
                        factors.append(n//i)
      
ans = 10**18
factors.sort()
for x in factors:
        y = n // x
        ans = min(ans, y-1+x-1)
  


print(ans)

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

seisu_tuple = []
for a in range(1,sqrt_n+1):
    if n/a == math.floor(n/a):  
        seisu_tuple.append((a,n/a))
bunkai_list_sum = [sum(x) for x in seisu_tuple]
min_tuple = seisu_tuple[bunkai_list_sum.index(min(bunkai_list_sum))]
print(int(sum(min_tuple) - 2))

Solution (Python):
import sys


import math
from fractions import gcd
from collections import deque
import bisect

sys.setrecursionlimit(1000000)


def main():
    
    

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


if __name__ == "__main__":
    main()

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

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

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

Solution (Python):


N = int(input())
end = int(N ** 0.5)

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

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

def main():
    n = int(input())
    root = int(math.sqrt(n))
    ans = 10**100
    for i in range(1,root+1):
        if n%i==0:
            ans = min(ans,i+n//i)
        else:
            pass
    print(ans-2)

if __name__=='__main__':
    main()

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

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

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

Solution (Python):
import math

N = int(input())
factor = []
tmp = int(math.sqrt(N))
while N%tmp!=0:
  tmp -= 1
print(int(tmp+(N/tmp)-2))

Solution (Python):
N = int(input())
import math
ans = N - 1
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())
sqrtN = int(math.sqrt(N))
x = 0
 
for i in range(1,sqrtN+1)[::-1]:
    if N % i == 0:
        x = i
        break
 
y = N // x
print(x+y-2)

Solution (Python):
import math
N = int(input())
a = 1
b = N
nn = math.sqrt(N)
n = math.ceil(nn)

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

print(a + b -2)

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

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

N = int(input())
ans = solve(N)
print(ans)

Solution (Python):
import math

n = int(input())

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

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

Solution (Python):
import math

N = int(input())

step = N - 1

for i in range(2, N):
    if N % i == 0:
        if step > (i - 1) + ((N / i) - 1):
            step = (i - 1) + ((N / i) - 1)

    if i > math.sqrt(N):
        break
print(int(step))

Solution (Python):
import math

N=int(input().strip())

ans=N+2
for i in range(1,math.floor(N**0.5)+1):
    if N%i==0:
        a=i
        b=N//a
        if a+b<ans:
            ans=a+b

print(ans-2)

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

for x in range(1, int(n ** 0.5)+1):
  if n % x == 0:
    y = n/x
    li.append(x+y-2)  
     
result = min(li) 
print(int(result))

Solution (Python):

import math
import heapq

MOD = 10**9+7

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

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

print(ans)

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

import math

min_m=10**20

for i in range(1,N):

    if i*i > N:
        break

    if N%i==0:
        j=N/i

        if i+j < min_m:
            min_m=i+j

print(int(min_m-2))

Solution (Python):


N=int(input())
import math
ij=[N,N]
n=math.floor(math.sqrt(N))

for itemp in range(n):
    i=itemp+1
    if N%i==0:
        if sum(ij)>i+N/i:
            ij=[i,N/i]
print(int(sum(ij)-2))

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

Solution (Python):
import math

N = int(input())
ans = N

for x in range(1, int(math.sqrt(N)) + 1):
    if N % x == 0:
        if ans > x + int(N / x) - 2:
            ans = x + int(N / x) - 2
print(ans)

Solution (Python):
import math
x = int(input())
i = int(math.sqrt(x))
while (i < x):
    if (x%i == 0):
        print (int((x/i)+i)-2)
        break
    i -= 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

def main():
    Min = 2000000000000
    divisors = make_divisors(int(input()))
    if len(divisors)%2==1:
        divisors.append(divisors[len(divisors)-1])
    
    for i in range(0,len(divisors)-1,2):
        Min = min(divisors[i]+divisors[i+1],Min)
    print(Min-2)

main()

Solution (Python):
n = int(input())
r = int(n**0.5)
revList = [i for i in range(r+1)]
revList = revList[1:]
revList.reverse()

for i in revList:
  if n % i == 0:
    res = int(n/i) + i - 2
    break
print(res)

Solution (Python):
import math

n = int(input())
a = int(math.sqrt(n)) + 1

res = 10 ** 12

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

print(res)

Solution (Python):
if __name__ == '__main__':

	n = int(input())
	m = int(n//2)

	end = n - 1
	for x in range(2,int(n**0.5)+1):
		if n % x == 0:
			y = n // x
			end = min(x+y-2,end)

	print(end)

Solution (Python):
n = int(input())
ans = 10**20
a = n ** 0.5
a = int(a)
for i in range(a+1):
  if i ==0:
    continue
  if n % i != 0:
    continue
  j = n/i
  j = int(j)
  ans = i+j-2
print(ans)

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

Solution (Python):
n = int(input())
ans = n
for i in range(1, 1000001):
    if n % i == 0:
        if ans > (i-1) + (n//i -1):
            ans = (i-1) + (n//i -1)

print(ans)

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

print(int(min(list)))

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

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

print(i-1+j-1)

Solution (Python):
import numpy as np
N=int(input())
qN=int(np.sqrt(N))
d = [i +  N//i - 2 if N%i==0 else 10**13 for i in range(1,qN+1)]
print(min(d))

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

Solution (Python):
N = int(input())
limit_of_a = int(pow(N, 1/2))+1

result = 1000000000001

for a in range(1, limit_of_a):
    if N % a == 0:
        b = N // a
        result = min(result, a+b-2)

print(result)

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


def main():
    N = int(input())
    rslt = divisor(N)
    print(rslt[-1][0] + rslt[-1][1] - 2)
    return


main()

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


def main():
    N = int(input())
    print(divisor(N)[-1][0] + divisor(N)[-1][1] - 2)
    return


main()

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

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

ans = i-1 + j-1
print(ans)

Solution (Python):
n=int(input())
ans=10**18
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())
n = round(N**0.5)
a = 0
b = 0
for i in range(n):
    if N%(n-i)==0:
        a = n-i
        b = int(N/a)
        break
print(a+b-2)

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

Solution (Python):

import sys

import math












def main():
    n = int(sys.stdin.readline().rstrip())

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

if __name__ == "__main__":
    main()

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

Solution (Python):
import math

N = int(input())

route_N = math.sqrt(N)




ans = 10e+12

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

print(int(ans))

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

Ans = 10**12

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

Solution (Python):
import math
a = int(input())
b = math.floor(a**0.5)
for i in range(b):
  if a % (b-i) == 0:
    c = b-i
    d = a //(b-i)
    break
print(c+d-2)

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

print(int(ans-2))

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

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

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

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

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

R = divisor(n)
S = []
for i in range(len(R)):
  S.append(R[i] + n//R[i] - 2)
  
print(min(S))

Solution (Python):
N = int(input())
ans = N - 1
a = 2
while a*a <= N:
    b = N // a
    if a * b == N:
        ans = min(ans, a + b - 2)
    a += 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)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors
  
x = make_divisors(n)
div = sorted(x)[len(x)//2]
print(n // div + div - 2)

Solution (Python):
import math
n = int(input())
ans = 10e+12
for a in range(1, int(math.sqrt(n))+1):
    if n % a == 0:
        b = n // a
        x = a + b - 2
        ans = min(x, ans)
print(ans)

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

Solution (Python):
import math
n = int(input())
g = 10 ** 15
a = math.floor(math.sqrt(n))
for i in range(1, a + 1):
    b = math.floor(n / i)
    if i * b == n:
        f = i + b - 2
        if g >= f:
            g = f
print(g)

Solution (Python):
import math
n = int(input())
g = 10 ** 15
a = math.floor(math.sqrt(n))
for i in range(1, a + 1):
    b = math.floor(n / i)
    if i * b == n:
        f = i + b - 2
        if g >= f:
            g = f
print(g)

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(i + j -2)

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