Problem:
 Score : 300 points    Problem Statement Takahashi is standing on a multiplication table with infinitely many rows and columns.  The square (i,j) contains the integer i \times j . Initially, Takahashi is standing at (1,1) .  In one move, he can move from (i,j) to either (i+1,j) or (i,j+1) .  Given an integer N , find the minimum number of moves needed to reach a square that contains N .      Constraints  2 \leq N \leq 10^{12}  N is an integer.         Input Input is given from Standard Input in the following format:  N       Output Print the minimum number of moves needed to reach a square that contains the integer N .        Sample Input 1 10      Sample Output 1 5  (2,5) can be reached in five moves. We cannot reach a square that contains 10 in less than five moves.       Sample Input 2 50      Sample Output 2 13  (5, 10) can be reached in 13 moves.       Sample Input 3 10000000019      Sample Output 3 10000000018  Both input and output may be enormous.

Solution (Python):
import math

N = int(input())

minimum = None
for i in range(1, int(math.sqrt(N) + 1)):
    is_dividable = N % i == 0
    if is_dividable:
        j = int(N / i)
        foo = i + j - 2
        minimum = foo if minimum is None else min(minimum, foo)

print(minimum)

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

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

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

Solution (Python):
n =int(input())
a =10**12

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

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

print(MAX+N//MAX-2)

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

N = int(input())

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

print(ans)

Solution (Python):
n=int(input())
i=1
l=[]
m=[]
while i<=n**0.5:
    if n%i==0:
        l.append(i)
        m.append(n//i)
        i+=1
    else:
        i+=1
o=len(l)
a=[]
for j in range(o):
    a.append(l[j]+m[j])
print(min(a)-2)

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

min = n + 1

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

print(min)

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

a=100000000000000

for i in range(n):
	if i==0:
		continue
	if i*i>n:
		break
	if n % i == 0:
		b = n//i
		a = min(a,b+i-2)

print(a)

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

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


i = 1
l = []
while i*i <= n:
    if n%i==0:
        l.append(i)
        l.append(n//i)
    i+=1

l.sort()
a = l[len(l)//2]
b = l[len(l)//2-1]
print(a+b-2)

Solution (Python):
n = int(input())
ans = 10**12

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

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

factor_a = 0
for i in range(1, int(np.sqrt(n)) + 1):
    if n % i == 0:
       factor_a = i
       
factor_b = n // factor_a



print(factor_a - 1 + factor_b - 1)

Solution (Python):
import math
n = int(input())
ans = n-1

for i in range(1, math.ceil(math.sqrt(n))+10):
     if n%i==0:
         ans = min(ans, i+(n//i)-2)
        
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)






a= max(divisors)
b=n//a


print(a+b-2)

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

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

ans = 1e12 + 5
for i in range(1, N + 1):
    j = N / i
    if (i > j):
        break
    if (N % i != 0):
        continue
    ans = min(ans, i + int(j) - 2)
print(ans)

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

Solution (Python):
import math

N = int(input())

ans = N-1

sqN = int(math.sqrt(N))

for i in range(1,sqN+1):
    if N % i != 0:
        continue
    else:
        a = i
        b = N // i
        ans = min(ans, a+b-2)

print(ans)

Solution (Python):
def divisor(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)
    return d

n = int(input())

ans = 10**12
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())
num=int(n**(1/2))
min=10**12
for i in range(1,num+1):
    if n%i==0:
        if min>i+(n//i)-2:
            min=i+(n//i)-2
print(min)

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

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

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
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

def main():
    n=int(input())
    n_list=make_divisors(n)
    len_list=len(n_list)
    if len_list%2==1:print(2*n_list[len_list//2]-2)
    else:
        print(n_list[len_list//2-1]+n_list[len_list//2]-2)

if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
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

def main():
    n=int(input())
    n_list=make_divisors(n)
    len_list=len(n_list)
    if len_list%2==1:print(2*n_list[len_list//2]-2)
    else:
        print(n_list[len_list//2-1]+n_list[len_list//2]-2)

if __name__=='__main__':
    main()

Solution (Python):

N = int(input())


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

    
    return divisors

yakusu =make_divisors(N) 
ans =[]
for i in yakusu:
    ans.append(sum(i)-2) 
print(min(ans))

Solution (Python):
import math

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

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

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

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

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

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

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

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

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

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

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

print(x + (N//x) - 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

p = make_divisors(n)
ans = float("inf")
for i in range(len(p)):
    if i < len(p) - 1:
        if p[i] * p[i+1] == n:
            ans = min(ans, p[i]-1+p[i+1]-1)
    if p[i] * p[i] == n:
        ans = min(ans, (p[i] - 1) * 2)
print(ans)

Solution (Python):
import math

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

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

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

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

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

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

import math
a = int(math.sqrt(n))

point = 1
for i in range(1,a+1):
  if n%i == 0:
    point = i
    
distance = (point-1) + int(n/point)-1
print(distance)

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

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

i = 1
ele = []
while i * i <= n:
    if n % i == 0:
        ele.append([i,n//i])
    i += 1

ans = 10**13
for i in range(len(ele)):
    ans = min(ans,ele[i][0]+ele[i][1]-2)
print(ans)

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

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

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

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

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

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

Solution (Python):


from itertools import combinations_with_replacement

int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


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 solve():
    n = II()
    divisors = make_divisors(n)

    ans = 1001001001001001
    for a, b in combinations_with_replacement(divisors, 2):
        if a * b != n:
            continue
        step = (a-1) + (b-1)
        ans = min(step, ans)
    print(ans)



if __name__ == '__main__':
    solve()

Solution (Python):


int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    n = II()

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

    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
import math
N = int(input())
num = 0
SQRTN = int(math.sqrt(N))
for i in range(1,SQRTN+1):
   if N % i == 0:
       num = i 

num_2 = N//num
print(num + num_2 -2)

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

Solution (Python):
import math
n=int(input())
m=math.ceil(math.sqrt(n))
list=[]

for i in range(1,m+1):
  if n%i==0:
    s=n//i
    t=s+i
    list.append(t)
list.sort()
print(list[0]-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)
  if len(divisors) % 2 != 0:
    return divisors[-1]*2
  else:
    return divisors[-1] + divisors[-2]

n = int(input())

print(max(make_divisors(n)-2,0))

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

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

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

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

k = int(N**0.5) + 1
ans = N

for a in range(2, k):
    tmp = 0
    if N % a == 0:
        tmp = N//a + a
        if ans > tmp:
            ans = tmp

if ans < N:
    print(ans - 2)
else:
    print(N - 1)

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

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

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

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

Solution (Python):
N = int(input())
ans = float('inf')
i = 1
while i**2 <= N:
    if N % i == 0:
        ans = min(ans, (i-1)+(N//i - 1))
    i += 1
print(ans)

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

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

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


MAX = 1
i = 1
while i <= n ** 0.5:
    if n % i == 0:
        MAX = max(MAX, i)
    i += 1
ans = abs(n // MAX + MAX - 2)
print(ans)

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

max_i = 1
i = 1
while i*i <= n:
    if (n//i)*i == n:
        max_i = i
    i += 1

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

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n=I()
i=int(math.sqrt(n))
while i>0:
    if n%i==0:
        ans=i+n//i-2
        break
    i-=1
print(ans)

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

ca = int(n ** (1 / 2))
while True:
    if n % ca == 0:
        ca_b = n // ca
        break
    ca -= 1

print(ca - 1 + ca_b - 1)

Solution (Python):
n = int(input())
stop = int(n**0.5) + 1
min_count = 10 ** 100
for a in range(1, stop):
    if n % a != 0:
        continue
    else:
        b = n // a
    count = a + b - 2
    if count < min_count:
        min_count = count
print(min_count)

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

ans = n - 1
for i in range(1, n):
    if i * i > n:
        break
    if n % i != 0:
        continue
    ans = min(ans, i + (n // i) - 2)

print(ans)

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

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

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

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


min = n
for i in range(1,m+1):
  if n%i == 0:
    waru = i
    shou = n//i
    
    if (waru+shou-2) < min:
      min = waru+shou-2
print(min)

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

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

Solution (Python):
import numpy as np

N = int(input())

ans = 1000000000000000
for i in range(1, int(np.sqrt(N)) + 2):
    if N % i != 0:
        continue
    num = i + N // i - 2
    if ans > num:
        ans = num
print(ans)

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

Solution (Python):
n = int(input())
l = []
for i in range(1,n):
    sur = n%i
    ans = n/i
   
    if ans < i:
        break
    elif sur == 0:
        l.append(i)
l.sort(reverse=True)
max = l[0]
max_op = n/max
ite = max-1+max_op-1
print(int(ite))

Solution (Python):
import math
n = int(input())
mn = 10 ** 12
for a in range(1, math.ceil(math.sqrt(n)) + 1):
    b = n // a
    if a + b < mn and a * b == n : mn = a + b
print(mn - 2)

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

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

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

times = []

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

print(min(times))

Solution (Python):
n = int(input())
ans = float('inf')
for i in range(1, int(n**(1/2))+1):
    a, b = divmod(n, i)
    if b == 0:
        ans = min(ans, a+i-2)
print(ans)

Solution (Python):
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect



import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial, log, log10, log2
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  n = int(readline())
  n2 = ceil(sqrt(n)) + 1
  ans = INF
  for i in range(1,n2):
    j = n//i
    if i*j==n:
      ans = min(ans, i+j-2)
  print(ans)
  
  
  
  
if __name__ == '__main__':
  main()

Solution (Python):
import math
N = int(input())
n = round(math.sqrt(N))
counter = 0
for i in range(n):
		if N%(n-i) == 0 and counter == 0:
			counter+=1
			var1=(n-i)
			var2=N/(n-i)
            
print(int(var1+var2-2))

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

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

print(int(ans))

Solution (Python):
import math

N = int(input())
n = 0
m = 0

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

print(n + m - 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())
divisors=make_divisors(n)
if divisors[-1]**2==n:
    print(divisors[-1]*2-2)
else:
    print(divisors[-1]+divisors[-2]-2)

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

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

Solution (Python):
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


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

    N = ii()
    m = int(N ** .5)
    while N % m != 0:
        m -= 1
    else:
        print(int(N / m + m - 2))


if __name__ == '__main__':
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
ans = float('inf')
for i in range(1, int(n ** 0.5) + 1):
    x, y = divmod(n, i)
    if y == 0:
        ans = min(ans, x + i)
print(ans - 2)

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

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

Solution (Python):

n = int(input())

ans = [10 ** 14, 10 ** 14]
for i in range(1, int(pow(n, 0.5)) + 1):
    if n % i == 0:
        tmp = n // i
        if tmp + i < sum(ans):
            ans = [i, tmp]
print(sum(ans) - 2)

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

n = int(input())
p = divisor(n)
ans = n + 10
for x in p:
  if x*x > n:
    break
  y = n//x
  if ans > y+x:
    ans = y+x
print(ans - 2)

Solution (Python):

def inputlist(): return [int(j) for j in input().split()]

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

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

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

Solution (Python):
N = int(input())
gcdlst = []
for i in range(1, int(N ** 0.5) + 1):
    if N % i == 0:
        gcdlst.append(i)
        if i != N // i:
            gcdlst.append(N // i)
gcdlst.sort()
tmplen = len(gcdlst)
if tmplen % 2 == 0:
    tmplen = tmplen // 2
    ans = gcdlst[tmplen] + gcdlst[tmplen - 1] - 2
else:
    tmplen = tmplen // 2
    ans = (2 * gcdlst[tmplen]) - 2
print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n=II()
    ans=n+2
    for d in range(1,n+1):
        if d**2>n:break
        if n%d==0:
            ans=min(ans,d+n//d)
    print(ans-2)

main()

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

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

Solution (Python):
def make_divisors(n: int) -> list:
    """自然数nの約数を列挙したリストを出力する
    計算量: O(sqrt(N))
    入出力例: 12 -> [1, 2, 3, 4, 6, 12]
    """
    divisors = []
    for k in range(1, int(n ** 0.5) + 1):
        if n % k == 0:
            divisors.append(k)
            if k != n // k:
                divisors.append(n // k)
    divisors = sorted(divisors)
    return divisors


n = int(input())
div = make_divisors(n)
ans = 10 ** 18
for i in div:
    ans = min(ans, i + n // i - 2)
print(ans)

Solution (Python):
n = int(input())
divisors = []
for i in range(1, int(pow(n, 0.5)) + 1):
    if n % i == 0:
        divisors.append([i, n // i])
divisors = sorted(divisors, key= lambda x:x[1])
res = 0

for i in divisors[0]:
    res += i - 1

print(res)

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


n = int(input())
l = sorted(div(n))
ans = l[0][2] + l[0][1] - 2
print(ans)

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

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

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

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

Solution (Python):
import math 

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

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

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

answer=0

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

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


div = 0

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

print(div+(n//div)-2)

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

n = int(input())

ans = 10 ** 18

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

print(ans)

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

Solution (Python):
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


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


if __name__ == '__main__':
    main()

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

Solution (Python):
n = int(input())
ans = 10**12
for i in range(1,n+1):
    if i*i > n:break
    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)

    divisors.sort()
    return divisors


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

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
res = INF
for i in range(1,10**6+10):
    if n%i == 0:
        tmp = i + n//i - 2
        res = min(res, tmp)
print(res)

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    Move = 10**20
    for i in range(1, N + 1):
        if i ** 2 > N: break
        if N % i == 0:
            Move = min((i - 1) + (N // i - 1), Move)
    print(Move)

    return 0

if __name__ == "__main__":
    solve()

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


if __name__ == '__main__':
    main()

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.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():
    n = I()
    for i in range(int(n**0.5)+2)[::-1]:
        if not n%i:
            print(n//i+i-2)
            return
    return


if __name__ == "__main__":
    solve()

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

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

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

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

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

print(ans)

Solution (Python):

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

Solution (Python):
import math
n=int(input())
m=math.floor(math.sqrt(n))
i=1
bk=[0,0]
while i<=m:
  wk=n/i
  if math.floor(wk)==math.ceil(wk):
    bk[0]=wk
    bk[1]=i
  i+=1
next
print(math.floor(sum(bk))-2)