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):
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

n = int(input())
x = make_divisors(n)

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

Solution (Python):
import math
import itertools
input_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
yakusu_list = divisor(input_n)
yakusu_list.sort()

if (len(yakusu_list) % 2) == 1:
  tmp = yakusu_list[len(yakusu_list)//2 + 1 -1] + yakusu_list[-(len(yakusu_list)//2 + 1)]
  print(tmp -2)
else:
  tmp = yakusu_list[len(yakusu_list)//2 - 1] + yakusu_list[-(len(yakusu_list)//2)]
  print(tmp -2)

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())



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)

    divisors.sort()
    return divisors


c = make_divisors(N)
lenc = len(c)
if (lenc % 2)==0:
    a = c[lenc // 2 - 1]
    b = c[lenc // 2]
else:
    a = c[lenc // 2]
    b = a

print(a + b -2)

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


n = int(input())
low, up = make_divisors(n)
if len(low) != 1:
    
    
    
    
    
    print(low[-1] + up[-1] - 2)
else:
    print(n - 1)

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

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

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

max_div_num = 1

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

x = max_div_num
y = n // max_div_num

print(x + y - 2)

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

max_div_num = 1

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

x = max_div_num
y = n // max_div_num

print(x + y - 2)

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

max_div_num = 1

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

x = max_div_num
y = n // max_div_num

print(x + y - 2)

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

Solution (Python):
from sys import exit
import math

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

Solution (Python):
n=int(input())
def div(h):
    y=[]
    for i in range(1,int(h**0.5)+1):
        if n%i==0:
            y.append((i,n//i))
    m=float("inf")
    for a,b in y:
        m=min(m,a+b-2)
    return m
print(div(n))

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

start_digit = math.ceil(math.sqrt(N))

for i in range(start_digit, 0, -1):
    q, r = divmod(N, i)
    if r == 0:
        output = i+q-2
        break
        
print(output)

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

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

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

Solution (Python):
n=int(input())
result=float('inf')
for i in range(1,int(n**.5)+1):
  if i*(n//i)==n:
    result=min(result,abs(i+n//i)-2)
print(result)

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

Solution (Python):
import sys
import time
import math
import itertools as it
def inpl():
    return list(map(int, input().split()))
st = time.perf_counter()


N = int(input())

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


ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
ans = float("inf")
for i in range(1, n+1):
    if n%i==0:
        ans = min(ans, i+n//i)
    if i*i>n:
        break
print(ans-2)

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

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

def mass_search(x):
  divisor = 0
  limit = math.floor(math.sqrt(x))
  for i in range(1,limit+1):
    if N % i == 0:
      divisor = max(divisor, i)
  x = divisor
  y = N//divisor
  return x+y-2

print(mass_search(N))

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

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

Solution (Python):
import math
n=int(input())
x=math.floor(math.sqrt(n))
while True:
  if n % x==0:
    print((x+n//x)-2)
    break
  x-=1

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

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

print(A+B-2)

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

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

def resolve():
    N = int(input())
    factors = divisors(N)
    ans = float("inf")
    for x, y in factors:
        ans = min(ans, (x-1)+(y-1))
    print(ans)
    

    
if '__main__' == __name__:
    resolve()

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())
ans = n
divisor_num = divisor(n)

for i in divisor_num:
    j = n // i
    tmp = i + j - 2
    ans = min(ans, tmp)

print(ans)

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

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

Solution (Python):
import math

n = int(input())
ans = n-1
x = int(math.ceil(math.sqrt(n)))

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

print(ans)

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

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

print(min(ans))

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

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

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

N = int(input())
div = make_divisors(N)
ans = 10 ** 13
for d in div:
    ans = min(ans, d + N // d - 2)
print(ans)

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

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

Solution (Python):
def divisor(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n // i)

        i += 1

    return lower_divisors + upper_divisors[::-1]

n = int(input())
d = divisor(n)
if len(d) == 2:
    print(d[1] - 1)
elif len(d) % 2 == 0:
    k = len(d)//2
    u = d[k-1]
    v = d[k]
    print((u-1) + (v-1))
else:
    k = len(d)//2
    v = d[k]
    print((v-1)*2)

Solution (Python):

import math

n = int(input())
m = math.floor(math.sqrt(n))

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

Solution (Python):
import numpy
n = int(input())
l = []
ans = n

def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

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

Solution (Python):

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

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

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

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(sum(L[-1])-2)

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


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

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

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


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

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

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

print(ans)

Solution (Python):
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

n = int(input())

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

ans = n

for k in range(2, int(math.sqrt(n)) + 1):
    if n % k == 0:
        temp_1 = n/k
        temp_2 = k
        ans = min(ans,temp_1 + temp_2)

print(int(ans-2))

Solution (Python):
import math
n = int(input())
p = 10 ** 12
m = math.floor(math.sqrt(n))

for i in range(1,m + 1):
    if n % i == 0:
        j = n // i
        p = min(p,i-1+j-1)

print(p)

Solution (Python):
import math

n = int(input())

def solve():
  for k in range(2, int(math.sqrt(n)) + 1):
    if n % k == 0:
      return False
  
s = solve()
if s != False:
  print(n-1)
  exit()
  
ans = 10**12
for k in range(2, int(math.sqrt(n)) + 1):
  if n % k == 0:
    ans = min(ans,k+n//k)
  
print(ans-2)

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

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

Solution (Python):
def divisor(x):
    table = []
    i = 1
    while i * i <= x:
        if x%i == 0:
            table.append(i)
            table.append(n//i)
        
        i +=1
        
    table.sort()
    return table 
    
n = int(input())

l = divisor(n)
c = len(l)

ans = 100100100100100
for i in range(c):
    x = l[i] - 1
    y = l[c-i-1] - 1
    tot = x + y
    ans = min(ans,tot)
    
print(ans)

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

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

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

han=999999999999999999999999999999999999999999
b=0



for a in range(1,int(math.sqrt(N))+1):
    if N%a==0:
        A=N/a
        if A>a:
            gou=A-a
        else:
            gou=a-A
        b=a
        if gou<han:
            han=gou
            kot=A+a

print(int(kot)-2)

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

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

a=make_divisors(n)

b=len(a)

if b%2==0:
  c=int(b/2)-1
  x=a[c]
  y=a[c+1]
  print(x+y-2)
  
else:
  c=int((b+1)/2)-1
  x=a[c]
  print(x+x-2)

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

N = int(input())
A = []
for i in range(2,int(math.sqrt(N))+1):
    if N%i == 0:
        A.append(i + (N//i) - 2)
if not A:
    print(N-1)
else:
    print(min(A))

Solution (Python):
import math
n = int(input())
ans = n - 1
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):
import math
N = int(input())
for i in reversed(range(1, int(math.sqrt(N)) + 1)):
    if N % i == 0:
        print(i + (N // i) - 2)
        quit()

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

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

print(ans)

Solution (Python):
import math
N = int(input())
res = N
for i in range(1, int(math.sqrt(N)) + 1):
    j = N // i
    if j * i == N:
        res = min(res, j - 1 + i - 1)
print(res)

Solution (Python):

def solve():
    ans = 10**12
    for i in range(1, int(N**0.5)+1):
        if N % i == 0:
            ans = min(ans, i + (N//i) -2)
    if N == 2:
        print(1)
    elif N == 3:
        print(2)
    else:
        print(ans)
            
if __name__ == "__main__":  
    N = int(input())
    solve()

Solution (Python):
from collections import defaultdict

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

Solution (Python):
import sys
input = sys.stdin.readline
from collections import defaultdict, deque

x = int(input()); m = int(x ** 0.5)
while x % m: m -= 1
print(m + (x // m) - 2)

Solution (Python):
import sys, os, math, bisect, itertools, collections, heapq, queue

from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, 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()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


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

    N = ii()
    ret = MAX

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


if __name__ == '__main__':
    main()

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

Solution (Python):
import math

n = int(input())
ans = 10 ** 15
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):
import math
n=int(input())
a=0
b=10**12
for i in range(1, 1+int(math.sqrt(n))):
	if n%i==0:
		a=(i-1)+(n//i)-1
	if a<b:
		b=a
print(b)

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

steps = []

for x in range(int(n ** 0.5)):
  if n % (x + 1) == 0:
    steps.append(x + n // (x + 1) - 1)
print(min(steps))

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

steps = []

for x in range(int(n**0.5)):
  if n % (x+1)==0:
    steps.append(x+n//(x+1)-1)

print(min(steps))

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

steps = []

for x in range(int(n ** 0.5)):
    if n % (x + 1) == 0:
        steps.append(x + n // (x + 1) - 1)

print(min(steps))

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

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

Solution (Python):
from math import sqrt
 
N = int(input())
 
search_max = int(sqrt(N))
 
min_number = 10**12
for x in range(1, search_max + 1):
    if N % x == 0:
        y = N // x
        if x + y < min_number:
            min_number = x + y
print(min_number-2)

Solution (Python):
N = int(input())
search_max = int(N**0.5)
 
min_number = 10**12
for x in range(1, search_max + 1):
    if N % x == 0:
        y = N // x
        if x + y < min_number:
         
            min_number = x + y
print(min_number-2)

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

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

Solution (Python):
from math import sqrt

N = int(input())

search_max = int(sqrt(N))

min_number = 10**12
for x in range(1, search_max + 1):
    if N % x == 0:
        y = N // x
        if x + y < min_number:
            min_number = x + y

print(min_number-2)

Solution (Python):
def main():
    import math
    n = int(input())
    n_sq = int(math.sqrt(n)) + 1
    tmp = 10 ** 13
    for i in range(n_sq, 1, -1):
        if n % i == 0:
            j = n // i
            k = (i-1) + (j-1)
            if tmp > k :
                tmp = k
    if tmp != 10 ** 13:
        ans = tmp
    else:
        ans = n-1
    print(ans)


    
if __name__ == "__main__":
    main()

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

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

Solution (Python):


import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
INF = float("inf")

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

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

    print(ans)

if __name__ == "__main__":
    main()

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

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

ans=N
for i in range(1, int(N**0.5+1)):
    if N%i==0:
        a = N/i
        b = N/a
        up_ans = a + b -2
        ans = min(ans, up_ans)
    else:
        continue
print(int(ans))

Solution (Python):
import math
import sys

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

if __name__ == '__main__':
    main()

Solution (Python):
def Divisors(n):
    L=[]
    k=1
    while k*k <= n:
        if n%k== 0:
            L.append(k)
        k+=1
    return L

N=int(input())
T=Divisors(N)

M=10**20
for a in T:
    M=min(M,a+(N//a)-2)
print(M)

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

N = k()
ans = N-1

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

print(ans)

Solution (Python):
from itertools import product
n = int(input())

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

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

Solution (Python):
import numpy as np
N = int(input())
x = np.arange(1, int(N ** 0.5 + 1))
div = x[N % x==0]
print(int(np.min(div + N / div)) - 2)

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

Solution (Python):
import math

N = int(input())





memo = 10 ** 100
for i in range(1, int(math.sqrt(N)) + 1):
    if N % i == 0 and memo > (N // i) + i:
        memo = i + (N // i)

print(memo - 2)

Solution (Python):
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        tmp = []
        if n % i == 0:
            tmp.append(i)
            tmp.append(n//i)
        if(len(tmp)>0):
            divisors.append(sum(tmp))
    return divisors
def main5():
    n = int(input())
    k = make_divisors(n)
    print(min(k)-2)


if __name__ == '__main__':
    main5()

Solution (Python):
import sys, os, math, bisect, itertools, collections, heapq, queue

from decimal import Decimal
from collections import defaultdict, deque



sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, 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()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)


MOD = 10 ** 9 + 7
MAX = float('inf')


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

    N = ii()

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


if __name__ == '__main__':
    main()

Solution (Python):

def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n // i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


y = make_divisors(int(input()))

if len(y) % 2 > 0:
    print(y[len(y) // 2] * 2 - 2)
else:
    print(y[len(y) // 2 - 1] + y[len(y) // 2] - 2)

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

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

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


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

n_div = divisors(n)
arr_ = [int(i + n / i) for i in n_div]
print(min(arr_) - 2)

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

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

print(int(result-2))

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

div = n
result = 10**12

for i in range(1,1000001):
  if n % i == 0:
    div = n // i
    result = min(result, i+div)

print(int(result-2))

Solution (Python):
def make_divisors(n):
    ans = 10 ** 12 + 10
    i = 1
    while i*i <= n:
        if n % i == 0:
            t = 0
            if i != n // i:
                t = i + (n//i) - 2
            else:
                t = i * 2 - 2
            
            if ans > t:
                ans = t
        i += 1
    return ans

n = int(input())
print(make_divisors(n))

Solution (Python):
from math import sqrt
n=int(input())
m=int(sqrt(n)//1)

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

Solution (Python):
N=int(input())
check=1
while check**2<=N:
  if N%check==0:
    keep=N//check
  check+=1
print(keep+N//keep-2)

Solution (Python):
import math
n = int(input())
m = math.floor(math.sqrt(n)) + 1
ans = 10**12

for a in range(1,m+1):
    b = n/a
    if b.is_integer():
        move = a+b-2
    else:
        continue
    ans = min(ans,move)
print(int(ans))

Solution (Python):
import math

N = int(input())
even = False

if N % 2 == 0:
    even = True

factor1 = int(math.floor(N ** (1/2)))








while True:
    if N % factor1 == 0:
        factor2 = int(N / factor1)
        break
    else:
        factor1 -= 1

print(factor1 + factor2 - 2)

Solution (Python):
import math

n = int(input())

bi_factors = []

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

inf = float('INF')
ans = inf

for point in bi_factors:
    d = point[0] + point[1] - 2
    if ans > d:
        ans = d

print(ans)

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

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

Solution (Python):
import math

N = int(input())
min_move_count = 10**13

for i in range(1, int(math.sqrt(N)) + 1):
    if N % i == 0:
        move_count = i + (N // i) - 2
        if move_count < min_move_count:
            min_move_count = move_count

ans = min_move_count
print(ans)

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

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

Solution (Python):
import math

N = int(input())

min_move_count = float("inf")
for i in range(1, int(math.sqrt(N)) + 1):
    if (N / i).is_integer():
        move_count = i + (N // i) - 2
        if move_count < min_move_count:
            min_move_count = move_count

print(min_move_count)

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

Solution (Python):
def solve(n):
  l = []
  for i in range(int(n**(1/2))):
    if n % (i+1) == 0:
      a = i + 1
      b = n // a
      l.append(a+b-2)
  return min(l)

print(solve(int(input())))

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

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

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7






N = getN()
divisors = []
def make_divisors(n):
    for i in range(1, int(math.sqrt(n)) + 1):
        a, b = 0, 0
        if n % i == 0:
            a = i
            b = n // i
            divisors.append([a, b])

make_divisors(N)

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

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

a = N-1
for x in range(2, int(sqrt(N))+1):
  q, r = divmod(N, x)
  if r == 0:
    a = min(x-1 + q - 1, a)
print(a)

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

n = int(read())
lim = int(n ** 0.5)
fact = [1]
for i in range(2, lim + 1):
    if (n % i == 0):
        fact.append(i)
    else:
        pass

if (len(fact) == 1):
    ans = n - 1

else:
    tar = fact[-1]
    ans = tar + int(n // tar) - 2

print(ans)

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

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

list_ans=[]
for i in range(2,n_+1):
  if n%i==0:
    ans=i+(n//i)-2
    list_ans.append(ans)
    
  
if not list_ans:
  print(n-1)
  exit()
print(min(list_ans))

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