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

from itertools import combinations
import math

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

d=make_divisors(N)

if math.sqrt(N) in d:
    d.append(int(math.sqrt(N)))

dist=float('inf')
for i in d:
    j = N//i
    if i * j ==N:
        dist = min(dist,i+j-2)

print(dist)

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

from itertools import combinations
import math

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

d=make_divisors(N)

if math.sqrt(N)**2 ==N:
    d.append(int(math.sqrt(N)))

dist=float('inf')
for i in d:
    j = N//i
    if i * j ==N:
        dist = min(dist,i+j-2)

print(dist)

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

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

Solution (Python):
import math as m

n = int(input())
q = int(m.sqrt(n))

for i in range(q,0,-1):
    if n%i == 0:
        k = i
        l = int(n/i)
        break

print(int(k+l-2))

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

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

ans = float('inf')

for i in range(1,math.floor(n**0.5)+1):
    if n%i==0:
        tmp = i+n//i-2
        if tmp<ans:
            ans=tmp
print(ans)

Solution (Python):

import numpy as np
from collections import deque
import collections

mod = 10 ** 9 + 7
N = int(input())


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


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

Solution (Python):


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

    j = 1
    ans = N
    for i in range(1, int(N**0.5) + 1):
        if N % i == 0:
            j = int(N/i)
        tmp = i - 1 + j - 1
        if tmp < ans:
            ans = tmp            
    print(ans)


main()

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

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

ans = float('inf')
for a,b in ans_list:
    ans = min(ans, a+b-2)

print(ans)

Solution (Python):
import math

ii = lambda:int(input())
li = lambda:list(map(int,input().split()))
lix = lambda x:list(li() for _ in range(x))

def main(n):
    res = n+1
    ran = math.floor(math.sqrt(n))
    for x in range(1,ran+1):
        y,mod = divmod(n,x)
        if mod == 0:
            res = min(res, calc(x,y))
    return res

def calc(x,y):
    return x + y - 2

n = ii()
print(main(n))

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

def make_div(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 = N//make_div(N)[-1] + make_div(N)[-1] - 2

print(ans)

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

Solution (Python):
from math import sqrt
N = int(input())
Nsq = int(sqrt(N))
div = 1
for i in range(Nsq,1,-1):
    if N % i == 0:
        div = i
        break

print(div + N // div - 2)

Solution (Python):
import math
import itertools
n = int(input())
x = 1
for i in reversed(range(1, math.ceil(math.sqrt(n))+1)):
    if n % i == 0:
        x = n / i
        break

print(math.floor(x - 1 + n / x - 1))

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

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

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

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

Solution (Python):
import numpy as np
N = int(input())
MIN = 10**12 + 1

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

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

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

Solution (Python):
n = int(input())
ans = float('inf')

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

n = int(input())
ls = make_divisors(n)
d = 10 ** 13 + 1
for i in ls:
    d = min(d, (i - 1) + (n // i - 1))

print(d)

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

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

n = int(math.sqrt(N))
M = 0
for i in range(1,n+1):
  if N%i == 0:
    M = max(M,i)

ans = N//M + M -2

print(ans)

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

Solution (Python):
n = int(input())
def is_prime(num):
    import math
    if num == 2:
        return True
    elif num <  3 or num % 2 == 0:
        return False
    for i in range(3, int(math.sqrt(num)) + 1, 2):
        if num % i == 0:
            return False
    return True

if is_prime(n):
    print(n-1)
    exit()

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

Solution (Python):
from math import sqrt

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

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

def divisors(n, sort=False):
    """
    nの約数をO(√n)で列挙する
    """
    d = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            d.append((i, n//i))  
    if sort:
        d.sort()
    return d
l = []
for d1, d2 in divisors(N):
    m = d1 + d2
    l.append(m)
print(min(l) - 2)

Solution (Python):
import math

if __name__ == '__main__':
    n = int(input())
    ans_div = 0
    limit = math.ceil(math.sqrt(n))
    for i in range(1, limit + 1):
        if n % i == 0:
            ans_div = max(ans_div, i)
    print(ans_div + n // ans_div - 2)

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

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

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

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


if __name__ == "__main__":
    main()

Solution (Python):
import math

x = int(input())

n = math.ceil(math.sqrt(x))

for i in range(1,n+1):
    if x%i == 0:
        temp = i

ans = temp + x/temp -2
print(int(ans))

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

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

Solution (Python):
import math

n = int(input())

maxn = math.floor(math.sqrt(n))

for i in range(maxn):
    j = maxn - i
    if n % j == 0:
        a = j
        b = int(n/j)
        break

print(a + b - 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):
n=int(input())
high=[]
low=[]
for i in range(1,int(n**0.5+1)):
  if n%i==0:
    low.append(i)
    high.append(n//i)
ans=high[-1]+low[-1]-2
print(ans)

Solution (Python):
import math

N = 10000000019
N = 50
N = 10
N = int(input())

result = []
for i in range(1, math.ceil(math.sqrt(N))+1):
    if N % i == 0:
        result.append((i + (N // i)) - 2)

print(min(result))

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

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

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

num = int(n**0.5)+1
x = 0
x_min = 10**13
for i in range(1,num):
    if n%i==0:
        x = n//i+i-2
        if x_min > x:
            x_min = x
print(x_min)

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

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

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

n = int(N**0.5) + 1

for a in range(1, n):
    if N % a == 0:
        b = N // a
        ans = (a - 1) + (b - 1)
print(ans)

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

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

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

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

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

Solution (Python):


import sys
import math
import collections
import itertools
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def lcm(x, y) : return (x * y) // math.gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

N = I()

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

print(ans)

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

Solution (Python):
import math
def main():
    N = int(input())
    mi = 10**13
    for i in range(1, math.floor(math.sqrt(N))+1):
        if N % i == 0:
            m = i - 1 + (N//i) - 1
            if mi > m:
                mi = m
    print(mi)
if __name__ == "__main__":
    main()

Solution (Python):
from collections import deque
from math import sqrt

N = int(input())
step = deque()

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

print(min(step))

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

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

















N = int(input())
n = int(N**(0.5))
for i in range(n):
  c = n-i
  if N % c == 0:
    a = N/c
    break;
print(int(a+c-2))

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

Solution (Python):
import math

n = int(input())

div = math.floor(math.sqrt(n))

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

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

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



def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, 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 SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'


p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")



N=II()

L=list()

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

print(min(L))

Solution (Python):

import math
import numpy as np
 
n = int(input())
ans = np.inf
for i in range(1, int(math.sqrt(n))+1):
    if n%i==0:
        q = n/i 
        tmp = i+q 
        if tmp <= ans:
            ans = tmp 
print(int(ans-2))

Solution (Python):

import math
import numpy as np

n = int(input())
ans = np.inf
for i in range(1, int(math.sqrt(n))+1):
    if n%i==0:
        q = n//i
        tmp = i+q 
        if tmp <= ans:
            ans = tmp 
            i_ = i 
            q_ = q 

print(ans-2)

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

r=[]

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

print(min(r))

Solution (Python):
n = int(input())
div = []
for i in range(1, int(n**0.5)+1):
    if n % i == 0:
        div.append(i)
        if i != n // i:
            div.append(n//i)
i = 0
div.sort()
while True:
    if div[i]*div[i+1] == n:
        print(div[i]+div[i+1]-2)
        break
    elif div[i]*div[i] == n:
        print(div[i]+div[i]-2)
        break     
    else:
        i += 1

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

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

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

Solution (Python):
import  math

N = int(input())

root = int(math.sqrt(N))
sum = 10 ** 13

for i in range(1, root + 2):
    if N % i == 0 and int(N / i) + i - 2 < sum:
        sum = int(N / i) + i - 2

print(sum)

Solution (Python):
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

N = I()

ans = 10 ** 18
for i in range(1, int(sqrt(N))+1):
    if N % i != 0:
        continue
    j = N // i

    ans = min(ans, i+j-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+n//i)
    return divisors

n = int(input())
lis = make_divisors(n)
print(min(lis)-2)

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

Solution (Python):
N = int(input())
val = []
for a in range(int(N**0.5)+1):
  b, mod = divmod(N, a+1)
  if mod == 0:
    val.append( (a+1) + b - 2 )
print(min(val))

Solution (Python):
import math
import itertools

n=int(input())


res = 10**13


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

        res=min(res,a + b -2)


print(int(res))

Solution (Python):
import os

def main():
	n = int(input())
	list_a = make_divisors(n)
	min_num = 1000000000000
	for i in range(0,len(list_a),2):
		if n//list_a[i] == list_a[i]:
			min_num = list_a[i] * 2 - 2
			break
		if min_num < (list_a[i] + list_a[i+1] - 2):
			pass
		else:
			min_num = list_a[i] + list_a[i+1] - 2
	print(min_num)
	
			


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

	
if __name__ == "__main__":
	main()

Solution (Python):
import math
n = int(input())
n_list = []
for i in range(1, int(math.sqrt(n))+1):
    if n % i == 0:
        n_list.append((i, n//i))
sa = n-1
for x, y in n_list:
    if sa >= abs(x-1)+abs(y-1):
        sa = abs(x-1) + abs(y-1)
print(sa)

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

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

Solution (Python):
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd 
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) 


n = int(input())
for i in range(ceil(sqrt(n)), 0, -1):
    f = n / i
    j = floor(f)
    if f - j > 0: continue
    print(i + j - 2)
    sys.exit()

Solution (Python):
import math

n = int(input())
ans = []
for i in range(1, int(math.sqrt(n)+1)):
  if i * (n // i) == n:
    ans.append(i + (n//i) -2 )

print(min(ans))

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

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

cnt = 0
for i in range(1, int(n ** 0.5)+1):
    if n % i == 0:
        cnt = max(cnt, i)

print(cnt + n//cnt - 2)

Solution (Python):
import math
n = int(input())
d = {}
for i in range(1,(int(math.sqrt(n)))+1):
  if (n/i).is_integer():
    d.setdefault(i,n//i)
ans = []
for k,v in d.items():
  ans.append((k-1)+(v-1))
print(min(ans))

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

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

print(ans)

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

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

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

Solution (Python):
import math

n = int(input())
ans_min = 10 ** 13
for i in range(1, int(math.sqrt(n)) + 1):
    a, b = divmod(n, i)
    if b == 0:
        ans = a + i - 2
        if ans_min > ans > 0:
            ans_min = ans
print(ans_min)

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

i_max = int(n**(0.5)//1)

result = 10**12

for i in range(1, i_max+1):
    if n%i == 0:
        result = min(result, i+n//i-2)
print(result)

Solution (Python):
import math

N = int(input())
ans = []
k = int(math.modf(math.sqrt(N))[1])

for a in range(1, k+1):
    if N % a == 0:
        b = int(N / a)
        ans.append(a + b - 2)

print(min(ans))

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

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

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

Solution (Python):
import math

n = int(input())

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

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

ans = []

if N**(1/2) < 2:
    print(N-1)
    exit()

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


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

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

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

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

Solution (Python):
from math import floor, sqrt

n = int(input())

ans = n - 1
for i in range(2, floor(sqrt(n)) + 1):
    j, mod = divmod(n, i)
    if mod == 0:
        temp = i + j - 2
        if temp < ans:
            ans = temp
print(ans)

Solution (Python):
from numpy import sqrt
n = int(input())
q = int(sqrt(n)) + 1
for i in reversed(range(1,q)):
    if n%i == 0:
        print(n//i + i - 2)
        break

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

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

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

Solution (Python):
import math

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

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

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

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):
n = int(input())
min_ = n -1 
for i in range(1, int(n**0.5)+10):
    if n % i != 0:
        continue
    else:
        min_ = min(min_, i-1+(n//i)-1)
    
print(min_)

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

Solution (Python):
def I(): return int(input())

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

Solution (Python):
import sys
N=int(input())
ma=10**100
for i in range(1, 10**6+2):
  if N%i==0:
    ma=min(ma,((i-1)+(N//i)-1))
print(ma)

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

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

Solution (Python):
n = int(input())
for i in range(10**6+1):
    if i ** 2 >= n:
        break

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

print(j + n // j - 2)

Solution (Python):
N = int(input())
A = []
import math


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

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

def myAnswer(N:int) -> int:
   divisors = make_divisors(N)
   length = len(divisors)
   if(length % 2 == 1):
      return divisors[length//2]*2 - 2
   else:
      return divisors[length//2] + divisors[length//2 - 1] - 2



def modelAnswer():
   tmp=1
def main():
   N = int(input())
   print(myAnswer(N))
if __name__ == '__main__':
   main()

Solution (Python):
import math
n=int(input())
min=n-1
x=1
y=n
for i in range(1,int(math.sqrt(n)+1)):
  if n%i==0:
    if abs(i-n//i)<min:
      x=i
      y=n//i
      min=abs(i-n//i)
print(x+y-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)
if l[-1]**2==n:print((l[-1]-1)*2)
else:print(l[-2]-1+l[-1]-1)

Solution (Python):
N = int(input())
s =N+1
n = int(N**0.5) 
i = 1
while i<=n:
  if N % i != 0:
    i += 1
  elif N % i == 0 and N//i +i < s:
    s = N//i + i
    i += 1
  else:
    i += 1
print(s-2)

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

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

Solution (Python):

import io
import math
from math import *

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

Solution (Python):
N = int(input())
def divisor_all(n): 
    l = [1,n]
    for i in range(2,int(pow(n,1/2))+1):
        if n % i == 0:
            if i == n//i:
                l.append(i)
            else:
                l.append(i)
                l.append(n//i)
    l.sort()
    return l 
L = divisor_all(N)
ans = 10**12
for i in range(len(L)):
    ans = min(ans,(L[i]+N//L[i]))
print(ans-2)

Solution (Python):
import math
n = int(input())
m = n**0.5
ans = 1
x = 0 


for i in range(1,math.floor(m)+1):
    x += 1 
    if n%i==0:
        ans = i

print(math.floor(ans+ n/ans -2))

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 accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = []
for i in range(1, int(sqrt(N))+1 ):
  if N%i == 0:
    A.append(i + N//i -2)

print(min(A))

Solution (Python):
import math
def divi(D):
    C = math.sqrt(D)
    C = math.ceil(C)
    for i in reversed(range(1,C+1)):
        if D % i == 0:
            return(i+D // i)
A = divi(int(input()))
print(A-2)

Solution (Python):
import sys

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

n = int(sys.stdin.readline().rstrip())

def main():
    res = divisors(n)
    print(res[-1] + res[-2] - 2)

if __name__ ==  '__main__':
    main()

Solution (Python):
import math
import fractions
import sys
import itertools
import numpy as np
from collections import Counter

def input1():
	return int(input())


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


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

def keta(N):
	return len(str(N))



n=input1()

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

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

Solution (Python):
import math

n=int(input())

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

mindis=n

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

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










mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    import math
    s = math.sqrt(n)
    i = 1
    mi_ = float('inf')
    while i <= s:
        if n % i == 0:
            mi_ = min(mi_,i + n//i - 2)
        i+=1
    print(mi_)
if __name__ == '__main__':
  main()

Solution (Python):
import math

N = int(input())

s = int(math.sqrt(N))

while s >= 1:
    if N % s == 0:
        break;
    s -= 1

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

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

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

Solution (Python):
import math
n=int(input())
t=int(math.sqrt(n))
while n%t!=0:
  t-=1
a=t
b=n//a

print(str(a+b-2))

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

Solution (Python):

import sys
import numpy as np
import math

def L1_norm(x, y):
    return (x+y-2)

def solve(N: int):
    d = 10**12
    for i in range(1,int(math.sqrt(N))+1):
        if N%i==0:
            d = min(d, L1_norm(i, N//i))

    print(d)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    solve(N)

if __name__ == '__main__':
    main()