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

n_sq = int(n**(1/2))
fact = []
for i in range(1,n_sq+2):
    if n%i == 0:
        fact.append(i)
ans = n-1
for i in fact:
    if n//i + i-2<ans:
        ans = n//i +i-2
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]




import math



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

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

def get_divisors(num):
    divs = []
    for i in range(1, int(num**0.5)+1):
        if not num % i:
            divs.append((i, num // i))
    return divs

ans = float("inf")
d = get_divisors(n)
for a, b in d:
    ans = min(ans, a+b-2)
print(ans)

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

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, atan2
from operator import mul
from functools import reduce
sys.setrecursionlimit(10**8)

INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
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)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()

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


print(ans)

Solution (Python):
from sys import stdin

N = int(stdin.readline().rstrip())
ans = 10 ** 13
A = 1
while A ** 2 <= N:
    if N % A == 0:
        if A + (N // A) < ans:
            ans = A + (N // A)
    A += 1
print(ans - 2)

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

Solution (Python):
import math

N = int(input())

d = math.floor(N**(1/2))

ans = 0

for i in range(1,d+1):
	if N % i == 0:
		ans = i

ans_2 = N // ans

print(ans + ans_2 - 2)

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

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

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


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

    mn = float("inf")
    for i in range(1, int(sqrt(n)) + 1):
        q, r = divmod(n, i)
        if r == 0:
            mn = min(mn, i + q - 2)

    print(mn)


if __name__ == "__main__":
    main()

Solution (Python):

import sys
import math
sys.setrecursionlimit(200000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def fi(): return float(input())
def mfi(): return map(float, input().rstrip().split())
def lmfi(): return list(map(float, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()



import collections
class Devisor(int):
    def __init__(self, n: int):
        self.val = n

    def isprime(self):
        if self.val <= 1:
            return 0
        for i in range(2, int(math.sqrt(self.val)) + 1):
            if self.val % i == 0:
                return 0
        return 1

    def factorize(self):
        res = collections.defaultdict(int)
        n = self.val
        i = 2
        while i * i <= n:
            while n % i == 0:
                n //= i
                res[i] += 1
            i += 1
        if n != 1:
            res[n] += 1
        return res

    def divisor(self):
        n = self.val
        ret = list()
        for i in range(1, int(math.sqrt(n)) + 1):
            if n % i == 0:
                ret.append(i)
                ret.append(n // i) if i * i != n else None
        return ret



def main():
    N = ii()
    d = Devisor(N).divisor()
    m = 10**18
    for x in d:
        if x + N // x < m:
            m = x + N // x
    print(m - 2)
    return


if __name__ == '__main__':
    main()

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


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

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

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

ans = n-1

d = 1

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

Solution (Python):

from __future__ import division, print_function
from collections import defaultdict, Counter, deque
from future_builtins import ascii, filter, hex, map, oct, zip
from random import randint
from itertools import imap as map, izip as zip, permutations, combinations, combinations_with_replacement
from __builtin__ import xrange as range
from math import ceil
from _continuation import continulet
from cStringIO import StringIO
from io import IOBase
import __pypy__
from bisect import bisect, insort, bisect_left, bisect_right
import sys
import os
import re
sys.setrecursionlimit(9999)
inf = float('inf')
mod = int(1e9) + 7
mod_ = 998244353
N = 5001
 
'''
Check for special cases (n=1)
One wrong submission = 10 mins penalty!
do smth instead of nothing and stay organized
'''

def main():
	n = int(input())
	ans = inf
	for i in range(1, int(n**.5)+1):
		if n%i == 0:
			curr = i + (n//i) - 2
			ans = min(ans, curr)
	print(ans)


BUFSIZE = 8192
class FastI(IOBase):
	def __init__(self, file):
		self._fd = file.fileno()
		self._buffer = StringIO()
		self.newlines = 0
 
	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
		self.newlines = 0
		return self.buffer.read()
 
	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count("\n") + (not b)
			ptr = self._buffer.tell()
			self._buffer.seek(0, 2), self._buffer.write(
				b), self._buffer.seek(ptr)
		self.newlines -= 1
		return self._buffer.readline()
class FastO(IOBase):
	def __init__(self, file):
		self._fd = file.fileno()
		self._buffer = __pypy__.builders.StringBuilder()
		self.write = lambda s: self._buffer.append(s)
 
	def flush(self):
		os.write(self._fd, self._buffer.build())
		self._buffer = __pypy__.builders.StringBuilder()
def print(*args, **kwargs):
	sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop("end", "\n"))
	if kwargs.pop("flush", False):
		file.flush()
def gcd(x, y):
	while y:
		x, y = y, x % y
	return x
sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
	def bootstrap(cont):
		call, arg = cont.switch()
		while True:
			call, arg = cont.switch(to=continulet(
				lambda _, f, args: f(*args), call, arg))
	cont = continulet(bootstrap)
	cont.switch()
	main()

Solution (Python):
get = lambda: int(raw_input().strip())
getl = lambda: raw_input().strip()
gets = lambda: map(int, raw_input().strip().split())
getss = lambda n: [gets() for _ in xrange(n)]





N = get()
x = int(N ** 0.5)
for i in xrange(x, 0, -1):
    if N / i * i == N:
        print i + N / i - 2
        exit()

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

min_val = 10**27
for i in range(1,int(N**0.5)+1):
    if N%i==0:
        j = N//i
        min_val = min(min_val, i+j)

print(min_val-2)

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

Solution (Python):

import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

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

if __name__ == '__main__':
    main()

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

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

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

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

Solution (Python):
import math


def main():
    N = int(input())
    ans = N - 1
    rt = int(math.sqrt(N))
    for x in range(2, rt+1):
        if N % x == 0:
            y = N // x
            ans = min(ans, (x + y - 2))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):










n = int(input())

st = set()
for divisor in range(1, int(n ** 0.5) + 1):
    if n % divisor == 0:
        st.add(divisor + (n // divisor) - 2)
print(min(st))

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

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

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

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)
            
                

    
    return divisors

div = make_divisors(N)
ans = 10**13;

for i in range(len(div)):
    a = div[i]
    b = N//a
    ans = min(ans,a+b-2)
print(ans)

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

Solution (Python):
def read_values():
    return map(int, input().split())


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


def f():
    N = int(input())

    for a in range(int(N ** 0.5) + 1, 0, -1):
        if N % a != 0:
            continue
        b = N // a
        print(a + b - 2)
        return


if __name__ == '__main__':
    f()

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

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

Solution (Python):
n = int(input())
ans = 1e23
for x in range(1,1000000+1):
	if n%x: continue
	y = n//x
	ans = min( ans , y-1 + x-1 )
print(ans)

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

Solution (Python):
import queue

"""
N = int(input())



A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""
N = int(input())
s = 10000000000000
i = 1
while i*i <= N:
	if N % i == 0 and i+(N/i) < s:
		s = i+(N//i)
	i += 1
print(s-2)

Solution (Python):
import math

n = int(input())

ans = 10**12
for i in range(1,int(math.sqrt(n))+1):
    if n%i == 0:
        memo1 = i
        memo2 = n//i

        ans = min(ans,memo1+memo2)

print(ans-2)

Solution (Python):
from math import ceil
N = int(input())
X = []
for d in range(1, ceil(N ** 0.5) + 1):
    if N % d == 0:
        X.append([d, N // d])

ans = float('inf')
for d1, d2 in X:
    ans = min(ans, d1 + d2 - 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())
yakusu=make_divisors(n)
yakusu=sorted(yakusu)
ngs=len(yakusu)
if len(yakusu)%2==0:
    
    print(yakusu[int(ngs//2)]+yakusu[int(ngs//2)-1]-2)
else:
    
    print(yakusu[int(ngs//2)]+yakusu[int(ngs//2)]-2)

Solution (Python):
N=int(input())
def divisor(n):
    d=[]
    for i in range(1,int(n**.5)+1):
        x,y=divmod(n,i)
        if y==0:
            d.append(i)
    return d
d=divisor(N)
print(d[-1]+N//d[-1]-2)

Solution (Python):
from sys import stdin


def input():
    return stdin.readline()[:-1]


def intput():
    return int(input())


def sinput():
    return input().split()


def intsput():
    return map(int, sinput())


n = intput()

ff = 100000000000

i = 1
while i * i <= n:
    if n % i == 0:
        x, y = i, n // i
        dist = x + y - 2
        if dist < ff:
            ff = dist
    i += 1

print(dist)

Solution (Python):
import math
n = int(input())
ans = 10 ** 20

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

print(ans)

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

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

ans = 10**13
for a in l:
    if ans > a+N//a:
        ans = a+N//a
ans -= 2
print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n = int(input())
    r = int(n ** 0.5) + 1
    for i in range(r,0,-1):
        if n%i==0:
            print(i+n//i-2)
            break
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 make_divisors_without_own(n):
    r = make_divisors(n)
    r.remove(1)
    r.remove(n)
    return r
n = int(input())

r = make_divisors_without_own(n)
r.sort()
if len(r) == 0:
    print(n - 1)
else:
    a = r[len(r) // 2]
    b = n // a
    print(a - 1 + b - 1)

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

    divisors.sort()
    return divisors
import sys
input = sys.stdin.readline
def solve():
  n = int(input())
  a = make_divisors(n)
  ans = n-1
  for a1 in a:
    a2 = n//a1
    ans = min(ans,a1+a2-2)
  print(ans)
solve()

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

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

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

ans = n - 1
for i in range(2, n):
    if i * i > n:
        break

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

print(ans)

Solution (Python):
N = int(input())
ls = []
ans = 10**13
for i in range(1,int(N**0.5)+1):
  if N%i==0:
    j = N//i
    if abs(i-1)+abs(j-1)<ans:
      ans = abs(j-1)+abs(i-1)
print(ans)

Solution (Python):
n=int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
l=make_divisors(n)
ans=10**18
for i in l:
    j=n//i
    ans=min(ans,i+j-2)
print(ans)

Solution (Python):
from math import sqrt

N = int(input())

res = float("inf")
for i in range(int(sqrt(N)) + 1, 0, -1):
    if N % i == 0:
        res = min(res, i + N // i - 2)

print(res)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

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

print(a-1+b-1)

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

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

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

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

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

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

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

print(ans)

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

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

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

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


if __name__ == '__main__':
    print(main())

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

    
    return divisors

n = int(input())
divisors = make_divisors(n)
min = 10 ** 12
for i in divisors:
    if i:
        if sum(i) < min:
            min = sum(i)

print(min-2)

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

for i in range(int(N**.5) +1)[::-1]:
	if N%i==0:
		break

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

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

li=make_divisors(n)

if len(li)%2==0:
    x=len(li)//2
    y=x-1
    ans=li[x]+li[y]-2
else:
    x=len(li)//2
    ans=li[x]*2-2
print(ans)

Solution (Python):

N = int(input())

i = 1
ans = float("inf")

while i ** 2 <= N:

    if N % i == 0:

        j = N // i

        ans = min(ans , i + j - 2)

    i+=1

print (ans)

Solution (Python):

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
ans = INF
for d in range(1,int(math.sqrt(N))+1):
    if N%d == 0:
        ans = min(ans,d-1+N//d-1)

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())
divisors = make_divisors(n)
ans = float('inf')
for d in divisors:
    ans = min(ans, d + n // d)
print(ans - 2)

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

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

ans = 1000000000000000000
for i in range(1,upper+1):
    if n % i == 0:
        buf = i + n//i-2
        if buf < ans:
            ans = buf

print(ans)

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


from collections import deque, defaultdict
import itertools as ite
import sys
import math
import decimal

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
i = 1
ans = INF
while i * i <= N:
    if N % i == 0:
        ans = i + N / i - 2
    i += 1
print ans

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

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    a,b=0,0
    for d in range(1,int(1+n**.5)):
        if(n%d==0):
            a,b=d,n//d
    print(a-1+b-1)
resolve()

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

ans = float('inf')
for i in range(1,10**6+1):
    if N%i: continue
    j = N//i
    ans = min(ans, i+j-2)
print(ans)

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))



N = I()

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

ans = float('inf')
div = make_divisors(N)
for d in div:
    temp = d+N//d-2
    if temp<ans:
        ans = temp
print(ans)

Solution (Python):
N = int(input())
ans = float("inf")
for i in range(1, 10**6+1):
    q, m = divmod(N, i)
    if m==0:
        ans = min(ans, q+i)
print(ans-2)

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

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

print(ans)

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

x=N

import math
xr=math.ceil(math.sqrt(x))

LIST=[]
for i in range(1,xr+1):
    if x%i==0:
        LIST.append(i)
        LIST.append(x//i)

ANS=1<<60

for l in LIST:
    ANS=min(ANS,l-1+N//l-1)

print(ANS)

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

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    ans = float("inf")
    m = int(n**0.5)+1
    for i in range(1,m+1):
        if n%i == 0:
            j = n//i
            s = i+j-2
            if s < ans:
                ans = s
    print(ans)
    return


if __name__ == "__main__":
    solve()

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

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

ans = float("inf")
for i in divisor(n):
    j = n//i
    ans = min(ans, i-1+j-1)
print(ans)

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

ret = float('inf')
i = 1
while i * i <= N :
    if N % i == 0 :
        ret = min(ret, i + N // i - 2)
    i += 1
print(ret)

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

Solution (Python):
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')


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)
    
    return divisors

def sol():
    N = int(input())

    divs = divisors(N)
    ans = INF
    for d in divs:
        M = N // d
        ans = min(ans, M - 1 + d - 1)

    print(ans)

sol()

Solution (Python):
import sys
import math
from collections import Counter

input = sys.stdin.readline
sys.setrecursionlimit(100000)


def getN():
    return int(input())


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


def solve():
    return


def main():
    n = getN()
    ans = n + 1
    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0:
            tmp = i + n // i
            if ans > tmp:
                ans = tmp



    print(ans-2)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
i = 1
ans = n

while i * i <= n:
    j, m = divmod(n, i)
    if m == 0:
        ans = min(ans, i + j - 2)
    i += 1

print(ans)

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