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())
num=int(math.sqrt(n))
numa=0
numb=0
for i in range(num):
    if n%(num-i)==0:
        numa=num-i
        numb=n//numa
        break
print(numa+numb-2)

Solution (Python):
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.buffer.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

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

Solution (Python):
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.buffer.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

m = float('inf')
n = ri()
for i in range(1, int(n**0.5) + 1):
  a = n//i
  if a*i == n:
    if m > a+i:
      m = a+i
else:
  print(m-2)

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)
    A.append(int(N/i))
    
A.sort()
base = int(len(A)/2)

print(A[base]-1 +A[base-1] -1)

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

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

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

Solution (Python):
N = int(input())
check = N
if N > 10**6:
    check = 10**6+2
mi = N+1
for i in range(1,check+1):
    if N%i==0:
        if mi > i + (N//i):
            mi = i + (N//i)
print(mi-2)

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

out = n - 1
q, mod = divmod(n, 2)
if mod == 0 and q < out:
    out = q  
if n > 2:
    for m in range(3, int(n ** 0.5) + 1):
        q, mod = divmod(n, m)
        if mod == 0 and (q - 1) + (m - 1) < out:
            out = q - 1 + m - 1

print(out)

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

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

sqrt_N = N ** 0.5
ans = 10**18

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

print(ans)

Solution (Python):
import math

n = int(input())
ans = float('inf')

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

print(ans)

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

a = 0
b = 0

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

Solution (Python):
import numpy as np
import sys
sys.setrecursionlimit(10**6)

n=int(input())

m=int(np.sqrt(n)+1)

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

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

Solution (Python):
N=int(input())
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            upper_divisors.append(n//i)
        i += 1
    return lower_divisors,upper_divisors
a,b=make_divisors(N)
print(a[-1]+b[-1]-2)

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

Solution (Python):

N=int(input())
S_List=[i for i in range(1,int(N**0.5)+1,1) if N % i ==0]

Answer = 10**12
for i in range(len(S_List)):
    Current_Answer = int(S_List[i] + (N/S_List[i]) -2)
    if Current_Answer < Answer:
        Answer = Current_Answer

print(Answer)

Solution (Python):

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

Solution (Python):
n = int(input())
import math
x = math.ceil(math.sqrt(n))
for i in range(x,0,-1):
  if n % i == 0:
    xy = [i,n//i]
    break

print(sum(xy)-2)

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

Solution (Python):
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):
N = int(input())

ans = 10 ** 12
for i in range(1,int(N ** 0.5) + 1):
  if N % i == 0:
    if N // i + i < ans:
      ans = N // i + i

print(ans - 2)

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

Solution (Python):
N = int(input())
b = int(N**0.5)
while True:
    if N%b != 0:
        b -= 1
    else:
        break

print(int(b+N/b-2))

Solution (Python):
import numpy as np

N = int(input())

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

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

ans = list()
for i in range(int(math.sqrt(N))):
    i += 1
    if N % i ==0:
        j = N//i
        ans.append(i + j -2) 
    else:
        pass

print(min(ans))

Solution (Python):

N = int(input())
b = N**0.5//1.0
while True:
    if N%b != 0:
        b -= 1
    else:
        break
print(int(b+N/b-2))

Solution (Python):
n = int(input())
sqrtN = n**(1/2)
if sqrtN.is_integer():
    Pos = [int(sqrtN), int(sqrtN)]

else:
    for i in range(int(sqrtN), 0, -1):

        if n%i == 0:
            Pos = [i, n//i]

            break
print(sum(Pos) - 2)

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

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

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

a[1] = int(n/a[0])

print(ans)

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


print(get_nearest_div_pair(int(input())))

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


pairs = enum_div_pairs(int(input()))
print(min(i + j - 2 for i, j in pairs))

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

    st = [N + 1]  
    d = 2
    while d * d <= N:
        if N % d == 0:
            st.append(d + N // d)  
        d += 1

    print(min(st) - 2)


if __name__ == '__main__':
    main()

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

Solution (Python):
n = int(raw_input())
d = 1 
m = +float('inf')
while(d * d <= n):
	if n % d == 0:
		m = min(m, n/d -1 + d -1)
	d+=1
print m

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):
import math

n=int(input())
ans=1+n-2
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):
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())
lst = make_divisors(N)
lst.sort()
for i in range(N):
    if lst[i] * lst[i+1] >= N:
        break
if lst[i] ** 2 == N:
    print(lst[i] * 2 - 2)
else:
    print(lst[i+1]-1+lst[i]-1)

Solution (Python):
import sys
import math
N=int(input())
c=math.sqrt(N)
c=int(c)
L=range(1,c+1)
R=sorted(L,reverse=True)
for i in R:
  if N//i==N/i:
    k=N//i
    print(k+i-2)
    sys.exit()

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)
x = int(l[len(l) // 2] + n / l[len(l) // 2] - 2)

print(x)

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

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

ans = float("inf")
for i in range(len(ls)):
    x, y = ls[i]
    ans = min(ans, x + y - 2)

print(ans)

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

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

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

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

n = int(input())
l = sorted(divisor(n))

if len(l) % 2 == 1:
    i = l[len(l)//2]
    ans = i * 2 - 2
else:
    i = l[len(l)//2 - 1]
    j = l[len(l)//2]
    ans = i  + j - 2
    
print(ans)

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

INF = 100100100100100


def solve():
    N = int(input())
    n_m = int(math.sqrt(N) + 1)

    r = INF
    for i in range(1, n_m + 1):
        if N % i == 0:
            r = min(r, i + N // i)

    print(r - 2)


if __name__ == '__main__':
    solve()

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

divisors = make_divisors(N)
l = len(divisors)

a = divisors[(l-1)//2]
b = N // a

print(a+b-2)

Solution (Python):
N = int(input())
destination = (1, N)

i = int(N ** 0.5)
while 1 < i:
    if N % i == 0:
        destination = (i, N//i)
        break
    i -= 1

print(destination[0] + destination[1] - 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

def walk_on_multiplication_table(n):

    ans = 10**13
    yaku = make_divisors(n)
    yaku.sort()
    count = len(yaku)
    for i in range(int(count//2)):
        ans = min(ans, (yaku[i]+yaku[count-i-1]-2))

    if count % 2 == 0:
        return ans
    return min(ans, (yaku[int(count//2)]*2)-2)

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

if __name__ == '__main__':
    main()

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

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

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

Solution (Python):

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


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


def main():
    N = int(readline())
    target = make_divisors(N)[-2:]
    print(target[0] + target[1] - 2)


if __name__ == '__main__':
    main()

Solution (Python):
import math
N = int(input())
min_num = N+1

for i in range(1,int(math.sqrt(N))+1):

    if N % i == 0:
        if (i + (N // i)) < min_num:
            min_num = (i + (N // i))
print(min_num - 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 ** 13
for d in D:
    ans = min(ans, d + N // d - 2)

print(ans)

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

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

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

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

Solution (Python):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())

    i = int(n ** 0.5)

    while i >= 1:
        if n % i == 0:
            j = n // i
            print(i + n // i - 2)
            exit()
        i -= 1


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

Solution (Python):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())

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


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

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:
            j = n // i
            if min > i + j - 2:
                min = i + j - 2

    print(min)


if __name__ == "__main__":
    setrecursionlimit(10000)
    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[-1]


N = int(input())
a = make_divisors(N)
b = N // a

print(a + b - 2)

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

def getDivisors(x):
    anss = set()
    for d in range(1, int(x**0.5)+1):
        if x%d == 0:
            anss.add(d)
            anss.add(x//d)
    return sorted(anss)

divs = getDivisors(N)

ans = N
for div in divs:
    k = N//div
    ans = min(ans, div+k-2)

print(ans)

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

print(ans)

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

Solution (Python):
n = int(input())
c = 1
for i in range(1,int(n**0.5) + 1):
    if n%i == 0:
        c = max(c,i)

print(n//c +c -2)

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

    divisors.sort()
    return divisors

n = int(input())
L = len(make_divisors(n))
i,j = make_divisors(n)[L//2-1], make_divisors(n)[L//2]

if (n**0.5).is_integer():
    print(int(2*(n**0.5-1)))
else:
    print(i+j-2)

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

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

Solution (Python):
import sys

input = sys.stdin.readline

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

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
minc=float('INF')
ans = [1,1]
for i in range(1,10**6+1):
    if n%i==0:
        x,y = i,n//i
        sumn = x+y-2
        if(minc>sumn):
            minc=sumn
            
print(minc)

Solution (Python):

import math


def inp():
    return(int(input()))



def inlist():
    return(list(map(int, input().split())))



def instr():
    s = input()
    return(list(s[:len(s)]))



def invr():
    return(map(int, input().split()))


N = inp()

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

Solution (Python):

import math
n = int(input())

ans=10**13
for i in range(1, int(math.sqrt(n))+1):
    if n%i==0:
        tmp=i+n/i-2
        if tmp < ans:
            ans=tmp
    else:
        continue

print(int(ans))

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

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

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

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

ans = 1+n-2

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

print(ans)

Solution (Python):

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes) if b else print(no)





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

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

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

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

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

Solution (Python):
import math
n=int(input())
def sosu(x):
    a=1
    for i in range(2,int(math.sqrt(x))+1):
        if x%i==0:
            a=i
    return a
a=sosu(n)
if a==1:
    print(n-1)
else:
    b=n//a
    ans=(a-1)+(b-1)
    print(ans)

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

t = int(n**0.5+1)
ans = 10**13
for i in range(1, t):
  if n%i == 0 and i+n//i-2 < ans:
    ans = i+n//i-2
print(ans)

Solution (Python):
def solution(N):
    p, q = N, 1
    min_sum = p + q

    for i in range(2, int(N ** 0.5) + 1):
        m, r = divmod(N, i)

        if r == 0 and m + i < min_sum:
            min_sum = m + i
            p, q = m, i

    return p + q - 2

if __name__ == '__main__':
    N = int(input())
    a = solution(N)
    print(a)

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

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

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

Solution (Python):
import sys
from collections import Counter
from collections import deque
import math
import bisect
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

def f(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())
l=f(n)
ans=10**13
for i in l:
    ans=min(ans,i+n//i-2)
print(ans)

Solution (Python):
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)

mn = 10 ** 12
for i in d:
    if (n / i) % 1 == 0:
        mn = min(n//i + i, mn)

print(mn-2 if mn != n else mn-1)

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

from math import sqrt
M=int(sqrt(N))

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

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

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

Solution (Python):
from math import ceil

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

n = int(input())
divs = divisors(n)
ans = 10 ** 12
divs.sort()
for i in range(ceil(len(divs) / 2)):
    a = divs[i]
    b = divs[(i + 1) * (-1)]
    ans = min(ans, (a - 1) + (b - 1))

print(ans)

Solution (Python):
import sys

import math
from fractions import Fraction
import itertools

input=sys.stdin.readline
n=int(input())
m=math.ceil(pow(n,0.5))
for i in range(m):
    if n%(m-i)==0:
        p=m-i
        break
q=n//p
ans=q-1+p-1
print(ans)

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7



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


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

    div = make_divisors(n)

    res = f_inf
    for i in div:
        cost = i + n // i - 2
        res = min(res, cost)

    print(res)


if __name__ == '__main__':
    resolve()

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

Solution (Python):
n=int(input())
t=[]
for i in range(1,int(n**0.5)+1):
  if n%i==0:
    t.append(i)
hantei=10**12+1
for i in t:
  if hantei>((i-1)+n//i-1):
    hantei=((i-1)+(n//i)-1)
print(hantei)

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

minval = N

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

print(minval)

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

from math import sqrt

def divisor_enumeration(n):
    div = []
    for i in range(1, int(sqrt(n))+1):
        if n % i == 0:
            if n // i != i:
                div.append((i, n // i))
            else:
                div.append((i, i))
        
    return div


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

    d = divisor_enumeration(N)
    
    ans = 10**15
    for x, y in d:
        ans = min(ans, x + y - 2)

    print(ans)


if __name__ == "__main__":
    main()

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

Solution (Python):
def main():
    n = int(input())
    f = []
    i = 2
    while i * i <= n:
        if n % i == 0:
            f.append(i)
            if i * i != n:
                f.append(n // i)
        i += 1
    if n != 1:
        f.append(n)
    f.sort()
    answer = float("inf")
    for ff in f:
        answer = min(answer, ff + n // ff - 2)
    print(answer)


if __name__ == '__main__':
    main()

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

import math

n = int(math.sqrt(N)) + 1

mi = 10000000000000
for i in range(1, n+1):
    if N % i == 0:
        s = i + (N // i) - 2
        if mi > s:
            mi = s
    
print(mi)

Solution (Python):

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect




N = int(input())
a = int(N ** .5)

for num in range(a):
    num = a - num
    if N % num == 0:
        b = N // num
        
        print(b + num -2)
        sys.exit()

Solution (Python):
n = int(input())
tmp = 1
 
for i in range(1,10**10):
  if n%i == 0:
    if i <= n//i:
      tmp  = i
    else:
      break
  elif i >= n/i:
    break
      
print(tmp + (n//tmp) -2)

Solution (Python):
n = int(input())
tmp = 1
 
for i in range(1,10**6+1):
  if n%i == 0:
    if i <= n//i:
      tmp  = i
    else:
      break
  elif i >= n/i:
    break
      
print(tmp + (n//tmp) -2)

Solution (Python):
n = int(input())
tmp = 1
 
for i in range(1,10**6+1): 
  
  if n%i == 0:
    if i <= n//i:
      tmp  = i
    else:
      break
  elif tmp == 1 and i >= n/i:
    break
      
print(tmp + (n//tmp) -2)

Solution (Python):
n = int(input())
tmp = 1
 
for i in range(1,10**6+1):
  if n%i == 0:
    if i <= n//i:
      tmp  = i
    else:
      break
  elif tmp == 1 and i >= n/i:
    break
      
print(tmp + (n//tmp) -2)

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

Solution (Python):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

import math

n = ni()
nn = n
mn = 10**12
nums = [1]

i=2
while i<=math.ceil(math.sqrt(n)+1):
  if n%i==0:
    nums.append(i)
  i+=1

for num in nums:
  other = nn//num
  mn = min(mn, num+other-2)

print(mn)

Solution (Python):



n = int(input())

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

print(ans - 2)

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

min = 1
max = n

while True:
    if (max - min == 1):
        sqrt = min
        break
    ave = (min + max) // 2
    if (ave**2 > n):
        max = ave
    else:
        min = ave



for i in reversed(range(sqrt+1)):
    if (n % i == 0):
        ans = (n // i) + i -2
        break

print(ans)

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

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

print(ans)

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

print(min(can))

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

for i in range(2,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())
s=int(math.sqrt(n))
m=n-1
for a in range(1,s//1+1):
    if n%a==0:
        i=a
        j=n//a
        if i+j-2<m:
            m=i+j-2
print(m)

Solution (Python):
import math
N = int(input())
lim = N
half_lim = int(math.sqrt(N)//1)
lis = [1  for i in range(0,half_lim+1,)]

result = N
for i in range(2,len(lis)):
    if lis[i] == 1:
        if N % i ==0:
            tmp = i-1  + (N//i -1)
            if result > tmp:
                result = tmp
    else :
        continue

if result ==N:
    print(result-1)
else :
    print(result)

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

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

Solution (Python):
N = int(input())
for i in range(int(N**0.5),0,-1):
    if N%i == 0:
        break
print(N//i+i-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

mi = 10**15
for i in make_divisors(n):
    a = i;b = n//i
    mi = min(mi,a+b-2)

print(mi)

Solution (Python):
from math import sqrt

N = int(input())

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

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

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


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

ans = 10**18
for d in divisors(N):
    k = N // d

    ans = min(ans, d + k - 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

10
N = int(input())
divisors = make_divisors(N)
ans = float('inf')
div_len = len(divisors)
if div_len % 2 == 0:
    i = div_len // 2
    j = div_len // 2 - 1
    ans = divisors[i] + divisors[j] - 2
else:
    ans = divisors[div_len // 2] * 2 - 2
print(ans)

Solution (Python):
n = int(input())
i = 1
a,b = 1,n
while i*i <= n:
    if n % i == 0:
        a = i
        b = n//i
    i += 1


print(a+b-2)

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

    for i in range(1,n+1):
        if i*i>n:
            break
        if n%i==0:
            m=i
            l=n//i

    print(m-1+l-1)
    
if __name__=="__main__":
    main()

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

n = int(input())
T = divisor(n)
ans = 10**20
for t in T:
    dist = (t[0] - 1) + (t[1] - 1)
    ans = min(ans, dist)

print(ans)