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())
limit = int(n**0.5)
ans = ""
for i in range(1,limit+1):
  if n%i != 0: continue
  x,y = i, n//i
  if ans == "": ans = x-1+y-1
  elif ans > x-1+y-1: ans = x-1+y-1
print(ans)

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

Solution (Python):
import math
N = int(input())
ans = 10**13
for k in range(1,math.floor(math.sqrt(N))+1):
    if N % k == 0:
        ans = min(ans,k+N//k-2)
print(ans)

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

dsts = []
for x in range(1, N + 1):
    if x ** 2 > N: break
    
    if N % x == 0:
        dsts.append((x, N // x))

MY_INF = 10 ** 18
ans = MY_INF
for dst_x, dst_y in dsts:
    ans_tmp = abs(dst_x - 1) + abs(dst_y - 1)
    ans = min(ans, ans_tmp)

print(ans)

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

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

print(A[-1]+N//A[-1]-2)

Solution (Python):
def get_half_dividers(n):
    return {i for i in range(1, int(n ** 0.5) + 1) if n % i == 0}


N = int(input())

dividers = get_half_dividers(N)
print(min([max(0, d - 1) + max(0, (N // d) - 1) for d in dividers]))

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

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

Solution (Python):
import math

def f(n):
    divisor = [1]
    limit = math.ceil(math.sqrt(n))
    for n2 in range(2, limit+1):
        if n % n2 == 0:
            divisor.append(n2)
    n1 = max(divisor)
    n2 = n // n1
    print(n1 + n2 - 2)

n = int(input())
f(n)

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

m = 0
for i in range(2, math.ceil(math.sqrt(n)+1)):
  if n % i == 0:
    m = i

if m == 0:
  print(n-1)
else:
  print(n // m + m - 2)

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

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




mn=n-1
a=1
while a*a<=n:
    if n%a==0:
        b=n//a
        mn=min(a+b-2,mn)
    a+=1
print(mn)

Solution (Python):



import math

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

Solution (Python):
def integerornot(n):
    if isinstance(n,int):
        return True
    if isinstance(n,float):
        return n.is_integer()
    return False

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

Solution (Python):
def primelist(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

def factorization(n):
    plist = primelist(int(n**0.5))
    factor = []
    for p in plist:
        k = 0
        while n%p==0:
            k+=1
            n//=p
        if k>0:
            factor.append((p,k))
        if n==1:
            break
    if n!=1:
        factor.append((n,1))

    return factor

def 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 = divisors(n)
t = len(divs)
if t==2:
  print(divs[-1]-1)
elif t%2==0:
  print(divs[t//2-1]+divs[t//2]-2)
else:
  print(divs[t//2]*2-2)

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

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

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

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

length_list = []

for i in range(len(ND_list)):
    ND_i = ND_list[i]
    x, y  = ND_i[0], ND_i[1]
    length = x**2 + y**2
    length_list.append(length)

idx = length_list.index(min(length_list))
print(ND_list[idx][0] + ND_list[idx][1] -2)

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

Solution (Python):
N = int(input().rstrip())
l = []
flag = True
for i in range(1,int(N**0.5)+1):
    if N % i == 0:
        l.append(i)
num = len(l)
if num==1:
    print(N-1)
else:
    ans=N-1
    for a in l:
        b=N/a
        ans = min([ans, a+b-2])
    print(int(ans))

Solution (Python):
import sys

n, *lst = map(int, sys.stdin.read().split())
sqr = int(n ** 0.5) + 1
for i in range(sqr, 0, -1):
  if not n % i:
    print(i + n // i - 2)
    quit()

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

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

i = int(N ** (1/2))
ans = 10 **13

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


print(ans)

Solution (Python):
from math import sqrt

n = int(input())

i = round(sqrt(n))
while i > 0:
  if n % i == 0:
    print(i + n // i - 2)
    break
  i -= 1

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

x = 1
ans = N
while x**2 <= N:
  if not N%x:
    ans = min(ans, x + N//x - 2)
  x += 1
  
print(ans)

Solution (Python):
import math as m


def resolve():
    N = int(input())
    minT = 10**12
    for i in range(1, int(m.sqrt(N)) + 1):
        if N % i == 0:
            j = N // i
            minT = min(minT, i + j - 2)
    print(minT)


resolve()

Solution (Python):
import math

N = int(input())

def factortwo(N):
    factors = []
    for i in range(1, int(math.sqrt(N))+1):
        if N % i == 0:
            factors.append((i, N // i))
    return factors

print(sum(factortwo(N)[-1]) - 2)

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

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

Solution (Python):
n=int(input())
import math
import numpy as np
a=math.ceil(n**0.5)
for ii in np.arange(a,0,-1):
  b=n//ii
  if b*ii==n:
    print(ii-1+b-1)
    exit()

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

min = N

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

print(min)

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

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

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

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

end = int(math.sqrt(10**12))
result = 10**13
for i in range(1,end+1):
    j = n//i
    if i * j == n:
        result = min(result,i+j-2)
print(result)

Solution (Python):
import math

n = int(input())

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

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

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

count = 1
min_move=10**12

while count <= math.sqrt(N):
    if N % count == 0:
        min_move = min(min_move, (N//count)+count -2)
    count+=1

print(min_move)

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

minlen = 10**12
for i in range(1, int(math.sqrt(N))+1):
    if N%i == 0:
        minlen = min(minlen, i + N//i - 2)

if minlen == 10**9:
    print(N-1)
else:
    print(minlen)

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

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

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

Solution (Python):
import math
n=int(input())
flag=0
def sosuu(m):
    h=int(math.sqrt(m))
    lis=[1]
    for i in range(2,h+1):
        if m%i==0:
            lis.append(i)
    return lis
x=max(sosuu(n))
y=n//x
ans=x+y-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)
    divisors.sort()
    return divisors
N=int(input())
mem=make_divisors(N)
if len(mem)%2==0: ans=(mem[(len(mem)//2)-1]+mem[(len(mem)//2)])-2
else: ans=(mem[(len(mem)//2)]*2)-2
print(ans)

Solution (Python):


n = int(input())

count = 1
ans = 10**12
while(count <= (n)**0.5):
    if n % count == 0:
        ans_tmp = (count-1) + (n//count-1)
    ans = min(ans, ans_tmp)
    count += 1

print(ans)

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

i=int(N**0.5)
while N%i>0:
    i-=1

j=N//i
print(i+j-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())

D = make_divisors(N)

ans = 10**12+1
for d in D:
    b = N//d
    if d + b < ans:
        ans = d + b
print(ans-2)

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

num = int(math.sqrt(n))
div = []
for i in range(1, num+1):
  if n % i == 0:
    div.append([i, n//i])
  
ans = float('inf')
for i in div:
  temp = (i[0]-1) + (i[1]-1)
  if temp < ans:
    ans = temp
print(temp)

Solution (Python):
import math

N=int(input())

N2=int(math.sqrt(N))
mins=N-1

for i in range(1,N2+1):
    if N%i==0:
        mins=min(mins,(N//i-1)+(i-1))

print(mins)

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

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

a=make_divisors(n)
print(a[0]+a[1]-2)

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

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

l=make_divisors(n)

ans1=[]
ans2=[]

for value in l:
    ans1.append(value)
    ans2.append(n//value)


ans=10**13
for i in range(len(ans1)):
    ans=min(ans1[i]+ans2[i],ans)

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

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

Solution (Python):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    min = 10 ** 15
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0 and min > i + n // i - 2:
            min = i + n // i - 2
    print(min)


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

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



N = int(input())


div = get_div(N)
mov = []
append = mov.append
for x in div:
    y = N // x
    append(sum([x - 1, y - 1]))

print(min(mov))


cnt = 0

Solution (Python):
from itertools import product
n = int(input())
def factorization(num):
    result = []
    count = 0
    temp = num
    for i in range(2, int(num ** 0.5) + 1):
        if temp % i == 0:
            count = 0
            while temp % i == 0:
                count += 1
                temp /= i
            result.append([i, count])
    if temp != 1:
        result.append([temp, 1])
    if result == []:
        result.append([num, 1])
    return result
factors = factorization(n)
exps = [range(factor[1] + 1) for factor in factors]
ans = 1001001001001
for exp0 in product(*exps):
    f0 = 1
    for i in range(len(exp0)):
        f0 *= factors[i][0] ** exp0[i]
    f1 = n // f0
    ans = min(ans, f0 + f1 - 2)
print(int(ans))

Solution (Python):
n = int(input())
ans = 10 ** 12
for i in range(1, int(n ** 0.5 + 1)):
    if (n / i) % 1 == 0:
        ans = min(ans, ((n / i) - 1) + (i - 1))
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)
                
    return divisors

n_div = make_divisors(n)
list_ = []

for i in range(len(n_div)):
  list_.append(int(n_div[i] + (n / n_div[i])))

print(min(list_)- 2)

Solution (Python):
import itertools
import math
import fractions
import functools
n = int(input())

maximum = math.ceil(math.sqrt(n))
minimum = 10**20
for i in range(1,maximum+1):
    j = 0
    if n % i == 0:
        j = n / i
        minimum = min(minimum,i+j)

print(int(minimum-2))

Solution (Python):
import math

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

print(int(ans))

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

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

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

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

i=int(N**0.5)
while N%i>0:
    i-=1

j=N//i
print(i+j-2)

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

Solution (Python):
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

def main():
    import math
    n=I()
    mini=1e+13
    for i in range(1,int(math.sqrt(n))+1):
        if n%i==0:
            mini=min(mini,i+(n//i)-2)
    print(mini)
    

if __name__=='__main__':
    main()

Solution (Python):
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()

ans = float('inf')
for a in range(1, int(N**0.5)+1):
	if N % a == 0:
		b = N // a
		ans = min(ans, a + b - 2)
print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

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

Solution (Python):
import math

N = int(input())

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=[]
    for i in range(1,int((n**0.5))+1):
        if n%i==0:
            a,b=i,n//i
            if a<=b:
                l.append(a+b-2)
            else:
                break
    print(min(l))
resolve()

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

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

Solution (Python):


import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))

from collections import Counter
def resolve():
    N,=pin()
    ans=N+1
    for i in range(1,10**6+1):
        if N%i==0:
            j=N//i
            
            if j>0:
                ans=min(ans,i+j)
    print(ans-2)
    

resolve()

Solution (Python):
from math import sqrt
N = int(input())
ans = 10 ** 12
for i in range(int(sqrt(N))):
  if N % (i + 1) != 0: continue
  else: ans = min(ans, i + N // (i + 1) - 1)
print(ans)

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)
divisors.sort()
if len(divisors) % 2 == 1:
    print(2 * divisors[len(divisors) // 2] -2)
else:
    print(divisors[len(divisors) // 2] + divisors[len(divisors) // 2 - 1] - 2)

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


if __name__ == "__main__":
    main()

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


      divisors.append(n // i)
      break
  return divisors

N = int(input())
l = make_divisors(N)
a = l[0]
b = l[1]
print(a + b - 2)

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


      divisors.append(n // i)
  return divisors

N = int(input())
l = make_divisors(N)
a = l[len(l) - 1]
b = l[len(l) - 2]
print(a + b - 2)

Solution (Python):
n=int(input())
r=n**(1/2)
w=0
for i in range(1,int(r)+1):
  if n%i==0:
    w=i
x,y=w,n//w
if x!=1 and y!=1:
  print(x+y-2)
else:
  print(max(x,y)-1)

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

Solution (Python):


"""
pf={}
n = int(input())
for i in range(2,int(n**0.5)+1):
    while n % i == 0:
        pf[i] = pf.get(i,0)+1
        n//= i
if n > 1 : pf[n] = 1
print(pf)
"""
"""

def trial_division(n):
    if n < 2:
        return []

    prime_factors = []

    for i in range(2, int(n**0.5)+1):
        
        while n % i == 0:
            
            prime_factors.append(i)
            
            n //= i
    
    if n > 1:
        prime_factors.append(n)

    return prime_factors

n = int(input())

"""

""" TLE
n=int(input())

for i in range(1,10000):
    for j in range(1,i+1):
        seki=i*j
        if seki==n:
            print(i+j-2)
            exit()
"""


import sys
input = sys.stdin.readline
 
N=int(input())
ans=10**12
for i in range(1,int(N**0.5)+1):
    if N%i==0: 
        ans=min(ans,i+N//i) 
print(ans-2)

Solution (Python):
import itertools
n = int(input())
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
d = divisor(n)
l = float('inf')
for i in range(len(d)):
    l = min(n // d[i] + d[i] - 2,l)
print(l)

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

Solution (Python):
n = int(input())
divs = []
for i in range(1, int(n ** 0.5) + 1):
  if n % i == 0:
    divs.append(i)
    if i != n // i:
      divs.append(n // i)
sdivs = sorted(divs)
lsdivs = len(sdivs)
if lsdivs % 2 == 0:
  a = sdivs[lsdivs // 2 - 1]
  b = sdivs[lsdivs // 2]
  print(a + b - 2)
else:
  a = sdivs[lsdivs // 2]
  print(a * 2 - 2)

Solution (Python):
import math


n = int(input())
a = int(math.sqrt(n))
while a > 0:
  if n%a == 0:
    s = a
    t = n//a    
    break
  a -= 1
print(s+t-2)

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

n = int(input())
li = divisors(n)
if len(li) % 2 == 0:
    a,b = li[len(li)//2-1],li[len(li)//2]
    print(a-1+b-1)
else:
    a = li[len(li)//2]
    print(2*a-2)

Solution (Python):
n = int(input())
def cal(n):
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            p = [i,n//i]
    return p
a = cal(n)
print(a[0]-1+a[1]-1)

Solution (Python):
import math

n=int(input())

x=int(math.sqrt(n))

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

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

main()

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

def main():
    N = int(input())
    N_divisors = make_divisors(N)
    mi = N_divisors[0] + N // N_divisors[0]
    for i in range(len(N_divisors)):
        c_mi = N_divisors[i] + N // N_divisors[i]
        if (c_mi <= mi):
            mi = c_mi
    print(mi-2)
    return 0
    
if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
i1 = round(N**0.5)
while True:
  if N%i1==0: break
  i1 -= 1

print(i1+round(N/i1)-2)

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

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

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

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

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

print(ans-1 + n//ans-1)

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

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

num = n + 1

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

print(num)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce


import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n = I()
sqrtn = sqrt(n)
for i in reversed(range(floor(sqrtn)+1)):
    if n % i == 0:
        a = int(n/i)
        print(a+i-2)
        exit()

Solution (Python):




import sys
import math
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n=int(readline())

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

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

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

Solution (Python):
n = int(input())
left = 1
right = n
ans_l = 1
while left <= right:
    left += 1
    right = n/left
    if n/left %1==0:
        right = int(n/left)
        ans_l = left
ans_r = n // ans_l
print(ans_l+ans_r-2)

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

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

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

m = 10**12
for i in range(2,int(n**0.5)+1):
    if n%i == 0:
        m = min(m,i+n//i-2)
    if i == int(n**0.5) -1:
        m = min(m,n-1)
if n <= 2:
    m = n-1
elif n == 3:
    m = 2
print(m)

Solution (Python):
import numpy as np
import sys
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(1000)

ten = 10 ** 6

def solve(N):
    
    ans = 2000000000000 + 10
    for i in range(1,ten+1):
        if N % i == 0:
            a = i
            b = N // i
            ans = min( ans , a + b - 2)
        
        if i > N :
            break
    
    print(ans)

if __name__ == "__main__":
    N = int(input())
    solve(N)

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

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

for i in range(int(N**0.5), 0, -1):
    if (N / i).is_integer():
        a = N // i
        b = N // a
        break

print(a+b-2)

Solution (Python):


N = int(input())
start = [1, 1]
end = [0, 0]
for i in range(1, int(N ** (1 / 2)) + 1):
    if N % i == 0:
        end[0] = i
        end[1] = N // i

print((end[0] - start[0]) + (end[1] - start[1]))

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

n = int(input())
t = divisor(n)
ans = float('inf')
for num in t:
  ans = min(ans, num + n//num - 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, n//i])
    
    return divisors

div_lst = make_divisors(N)

min_num = float("inf")
for d in div_lst:
    tmp = d[0]+d[1]
    if tmp < min_num:
        min_num = tmp

print(min_num-2)

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

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

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

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

Solution (Python):
import math

def main():
    n = int(input())
    m = math.sqrt(n)
    ans = []
    for i in range(1, int(m) + 1):
        div = n / i
        if not float.is_integer(div):
            continue
        ans.append((div+i)-2)

    print(int(min(ans)))


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
ans = []
for i in range(1,int(pow(N,0.5))+1):
    if N%i==0:
        ans.append(i+N//i)

print(min(ans)-2)

Solution (Python):
N = int(input())
ans = []
for i in range(1,int(pow(N,0.5))+1):
    j = N//i
    if i*j == N:
        ans.append(i+j)

print(min(ans)-2)

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

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

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

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


from math import sqrt

def divisor(num):
    max_num = int(sqrt(num))
    divisor_list = []
    for i in range(1, max_num + 1):
        if num % i == 0:
            divisor_list.append(i)
            divisor_list.append(num//i)
    sorted_divisor_list = sorted(divisor_list)
    return sorted_divisor_list

def main():
    l = divisor(n)
    n_i = l[len(l)//2 - 1]
    n_j = l[len(l)//2]
    dist = n_i - 1 + n_j - 1
    print(dist)

main()

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

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

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

d = 1
ans = n - 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())
from math import sqrt
root = int(sqrt(n))

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

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

Solution (Python):
def main():
    N = int(input())
    m = 1
    min_value = N**2
    while m**2 <= N:
        if N % m == 0:
            n = N // m
            value = (n - 1) + (m - 1)
            min_value = min([min_value, value])
        m += 1
    print(min_value)


if __name__ == '__main__':
    main()

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

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

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

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

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

Solution (Python):


import math

N = int(input())

mi = -1

for i in range(1, int(math.sqrt(N)) + 1):
    a = i
    if N % a != 0:
        continue

    b = N // a
    count = a + b - 2
    
    if mi <= -1 or mi > count:
        mi = count

print(mi)

Solution (Python):
import math

N = int(input())

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

print(N - 1)