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


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


div = make_divisors(N)

if div[-1] ** 2 == N:
    print(div[-1]*2 - 2)

else:
    x = div[-2] - 1
    y = div[-1] - 1

    print(x + y)

Solution (Python):
N = int(input())
sqrt = 1
for i in range(1,N+1):
    if((i**2)<=N and ((i+1)**2>N)):
        sqrt = i
        break

        
for i in range(sqrt):
    if(N%(sqrt-i)==0):
        a = sqrt-i
        break

b = int(N/a)
print(a-1+b-1)

Solution (Python):
import math
n = int(input())
move = 0
m = math.ceil(n ** (1/2))
for i in range(1, (m+1)):
    if n %  i == 0:
        move = i + (n/i) - 2
    else:
        pass
print(int(move))

Solution (Python):

import math


N = int(input())


def divisor(n):
    i = 1
    l = list()
    while i * i <= n:
        if n % i == 0:
            l.append(i)
            l.append(n // i)
        i += 1
    l = list(set(l))
    return l

l = sorted(divisor(N))
ans = 10 ** 12
for i in range(math.ceil(len(l) / 2)):
    ans = min(l[i] - 1 + l[len(l) - i - 1] - 1, ans)


print(ans)

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

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

ans = 1 + N - 2
while True:
    if i * i > N:
        break
    if N % i == 0:
        ans = min(ans, i + N//i - 2)
    i += 1
print(ans)

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

Solution (Python):
import sys
from math import ceil, sqrt

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())

sys.setrecursionlimit(10 ** 9)
INF = float('inf')


def main():
    N = INT()

    num = [i + 1 for i in range(ceil(sqrt(N)))]

    minimum = INF
    for i in num:
        if N % i == 0:
            temp = i + N//i
            if temp < minimum:
                minimum = temp

    print(minimum - 2)


if __name__ == '__main__':
    main()

Solution (Python):
import math
from functools import reduce

def factors(n):    
    return set(reduce(list.__add__, 
                ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

def prime(n1):
	for i in range(2, int(math.sqrt(n1))+1):
		if n1%i == 0:
			return False
	return True

n = int(input())
if prime(n):
	print(n - 1)
else:
	k = sorted(list(factors(n)))
	
	if len(k) % 2 != 0:
		if k[len(k)//2]*k[len(k)//2] == n:
			print(2*k[len(k)//2] - 2)
		

	else:
		s = k[len(k)//2 - 1] + k[len(k)//2]
		print(s - 2)

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

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

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

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

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

from math import sqrt
N = int(input())
a = make_divisors(N)

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

Solution (Python):
import math
n = int(input())
pair = []
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)
ans = float('inf')
for i in divisors:
  ans = min(ans, i + int(n / i))
print(ans-2)

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

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

Solution (Python):
import math

N = int(input())

a = int(math.sqrt(N))
b = 1

if N % a == 0:
	b = int(N / a)
else:
	a -= 1
	while a > 0:
		if N % a == 0:
			b = int(N / a)
			break
		a -= 1

if a*b == N:
	print(a + b -2)

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

Solution (Python):
import math


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


def main(n):
    if is_prime(n):
        return n - 1
    else:
        sqrt = int(math.sqrt(n))
        for i in range(sqrt, 1, -1):
            div, mod = divmod(n, i)
            if mod == 0:
                return i + div - 2


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

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

lis = []
for i in range(1,int((n**0.5) + 1)):
    if n % i == 0:
        lis.append(i)
        if i != n //i:
            lis.append(n//i)
            
lis.sort()
n2 = len(lis)
if n2 % 2 == 0:
    n2 = n2//2
    key = True
else:
    n2 = n2//2
    key = False

if key == True:
    a = lis[n2]
    b = lis[n2 -1]
else:
    a = lis[n2]
    b = lis[n2]
    
print(a-1+b-1)

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 = sorted(list(set(table)))
  l=len(table)
  if l==2:
      return n-1
  elif l%2==1:
      a=0
      x=l//2
  else:
      a=1
      x=l//2-1
      y=l//2
  if a==0:
    return table[x]*2-2
  if a==1:
    return table[x]+table[y]-2
print(divisor(N))

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

result = None
for i in range(1, int(N**0.5)+1):
    if N % i == 0:
        j = i + (N // i)
        if result is None or j < result:
            result = j

print(result - 2)

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

n = int(input())
divisors = make_divisors(n)
steps = min(d + (n // d) for d in divisors)
print(steps - 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
if (make_divisors(N)[-1])**2 ==N:
  print(2*make_divisors(N)[-1]-2)
else:
  print(make_divisors(N)[-1]+make_divisors(N)[-2]-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())

list_y = make_divisors(N)

point = len(list_y)
if point % 2 == 0:
    print(list_y[point // 2] + list_y[point // 2 - 1] - 2)
else:
    print(list_y[point // 2] * 2 - 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)
            divisors.append(n//i)

    divisors.sort()
    return divisors

n = int(input())

factor = make_divisors(n)
print((factor[len(factor)//2 - 1] - 1) + (factor[len(factor)//2] - 1))

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

Solution (Python):

N = int(input())

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

print(min([i+j for i,j in zip(sorted(div_num),sorted(div_num)[::-1])])-2)

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

ans = 10 ** 12 + 2
for a in range(1, int(n ** 0.5) + 1):
    b = n // a
    if n % a == 0 and a + b < ans:
        ans = a + b

print(ans - 2)

Solution (Python):
import sys
import math
n = int(input())
tmp = 10**12

for i in range(int(math.sqrt(n))+1, 0, -1):
    if n % i != 0:
        continue
    else:
        if tmp > (n//i)+(i)-2:
            tmp = (n//i)+i-2
print(tmp)

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
a = divisor(N)
b =  10**13

for i in a:
    b = min(b,i + (N / i))
    
print(int(b-2))

Solution (Python):
n = int(input())
def yks(n):
    yakusu = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            yakusu.append(i)
            if i != n // i:
                yakusu.append(n//i)
    yakusu.sort()
    return yakusu
g=yks(n)
p=len(yks(n))//2
if g[p]*g[p-1]==n:
    print(g[p]+g[p-1]-2)
else:
    print(2*g[p]-2)

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

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

    
    return divisors
p=make_divisors(n)

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

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

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

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

print(min(nums))

Solution (Python):

from math import ceil, sqrt

def solve():
    N = int(input())
    for i in range(ceil(sqrt(N)),0,-1):
        if N%i:
            continue
        else:
            return str(i+N//i-2)
        
if __name__ == '__main__':
    print(solve())

Solution (Python):
import math
N = int(input())
j = int(N)
start = int(math.sqrt(N))

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

print(i + j - 2)

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

a = [1, n]

for i in range(1, int(n**0.5)+1):
    j = n // i
    if n % i == 0 and a[0] + a[1] > i + j:
        a = [i, j]

print(a[0] - 1 + a[1] - 1)

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

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

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

Solution (Python):
n=int(input())
import math
list=[ ]

for i in range(1,math.floor(n**0.5)+1):
  if (n/i)%1==0:
    j=n/i
    list.append(i+j)

print(int(min(list)-2))

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

sq=math.floor(math.sqrt(N))

cond=0
for j in reversed(range(2,sq+1)):
  if N%j==0:
    print(j+N//j-2)
    cond=1
    break

if cond==0:
  print(N-1)

Solution (Python):
import math
n=int(input())
a=0
b=0

n_rt=math.sqrt(n)
if float.is_integer(n_rt)==True:
    print(2*int(n_rt-1))
else:
    for i in range(int(n_rt//1)):
        tmp=n%(n_rt//1-i)
        if tmp==0:
            y=int(n/(n_rt//1-i))
            print(int((n_rt//1-i)+y-2))
            break

Solution (Python):
import sys
import math

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins















def solve(inputs):
    N = int(inputs[0])
    
    min_diff = None
    for i in range(1, 1000001):
        if N % i == 0:
            a = N // i
            diff = a + i - 2
            if min_diff is None or min_diff > diff:
                min_diff = diff
    return min_diff


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

Solution (Python):
from math import sqrt, ceil

def min_mult(m):
  for i in xrange(int(ceil(sqrt(m))), 0, -1):
    if m % i == 0:
      return i, int(m/i)

def main():
  n = int(raw_input())
  a, b = min_mult(n)
  print(a-1 + b-1)

main()

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

answer_list=[]
for i in range(1, int((math.sqrt(N)))+1):
    if N % i == 0:
        s = N/i
        answer_list.append(s+i)

print(int(min(answer_list)) - 2)

Solution (Python):

import sys
from heapq import heappush, heappop
from math import sqrt

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

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

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

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

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

    
    return divisors
a=sorted(make_divisors(n))
b=len(make_divisors(n))
if b%2==1:
  m=(b-1)//2
  c=a[m]
  print(2*c-2)
else:
  c=a[((b-2)//2)]
  d=a[(b//2)]
  print(c+d-2)

Solution (Python):
N=int(input())
list=[]
for t in range(1,int(N**(1/2)+2)):
  if N%t==0:
    list+=[(t,int(N/t))]
mini=N+1
for (p,q) in list:
  if p+q<mini:
    mini=p+q
print(mini-2)

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

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

Solution (Python):
import sys

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

stdin = sys.stdin

ni = lambda: int(ns())
ns = lambda: stdin.readline()

N = ni()
ans = 0
if N > 1:
    div = divisor(N)
    
    if len(div) > 1:
        i = div[len(div)//2 - 1] - 1
        j = (N // (div[(len(div)//2) - 1]))  - 1
        ans = i + j
    else:
        ans = 1
elif N == 1:
    ans = 0
else:
    ans = 1

print(ans)

Solution (Python):
import math

N = int(input())

min_ = float('inf')

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

for n in range(1, x):
    r = N % n

    if r == 0:
        min_ = min(min_, n + N // n - 2)

print(min_)

Solution (Python):
import math

N=int(input())
n = N**0.5

if n % 1 == 0:
  print(math.floor(2* n -2))
else:
  n = int(round(n, 0))
  while N % n != 0 :
    n = n - 1
  b = N / n
  print(math.floor(n + b -2))

Solution (Python):
N = int(input())
temp = 0
answer = N

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

Solution (Python):
x = int(input())
import math
list = []
half = math.ceil(math.sqrt(x))
for i in reversed(range(half + 1)):
    if x % i == 0:
        print(int(i + x/i - 2))
        break

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 = []
for i in range(1,1000001):
  l.append(i*i) 

a = make_divisors(n)
b = 1
c = 1
if len(a) % 2 == 0:
  b = a[len(a)//2]
  c = a[len(a)//2-1]
else:
  b = a[(len(a)-1)//2]
  c = a[(len(a)-1)//2]
  
ans = b-1+c-1

import math
if n in l:
  ans = 2* math.sqrt(n) - 2
print(int(ans))

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

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

Solution (Python):
import math

n=int(input())

min=-1
for i in range(1,int(math.sqrt(n))+1):
    if n%i==0:
        j=int(n/i)
        calc=j+i-2
        if min==-1 or min>calc:
            min=calc

print(min)

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

from collections import defaultdict
import sys
sys.setrecursionlimit(1000)

MINV = 10**13

di = defaultdict(int)
tmp = n
for i in range(2, int(n**0.5)+1):
    while tmp % i == 0:
        di[i] += 1
        tmp //= i
if tmp != 1:
    di[tmp] += 1

def gettotal(di, keys, keyindex, nowa, nowb):
    key = keys[keyindex]
    mins = MINV
    if keyindex == len(keys) -1:
        for i in range(di[key]+1):
            a = key ** i
            b = key ** (di[key] - i)
            if nowa * a + nowb * b < mins:
                mins = nowa * a + nowb * b
        return mins
    for i in range(di[key] + 1):
        a = key ** i
        b = key ** (di[key] - i)
        res = gettotal(di, keys, keyindex+1, nowa * a, nowb * b)
        if res < mins:
            mins = res
    return mins

result = gettotal(di, list(di.keys()), 0, 1, 1)
print(result -2)

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

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


if __name__ == "__main__":
    resolve()

Solution (Python):
def main():
    n = int(input())
    x = int(n**0.5)
    while True:
        if n%x == 0:
            print(x+n//x-2)
            break
        x -= 1
        
if __name__ == '__main__':
    main()

Solution (Python):
import math

N = int(input())

max_n = int(math.sqrt(N))

for i in range(max_n):
  n = max_n - i
  if N % n == 0:
    break

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

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

ans = 1

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

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

Solution (Python):
import math
N=int(input())
end=int(math.sqrt(N)//1+1)
def func(i):
    d,m=divmod(N,i)
    if m==0:
        return i+d
    else:
        return 10**12+1
ret=min([func(i) for i in range(1,end)])-2
print(int(ret))

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

    
    return divisors

n = int(input())
divisors = make_divisors(n)
divisors.sort()
res = n*2
for i in range(int(len(divisors)/2+1)):
	if res > (divisors[i]+divisors[-(i+1)]-2):
		res = (divisors[i]+divisors[-(i+1)]-2)
print(res)

Solution (Python):
def md(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())
Y = md(n)

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

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

def divide(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
  
divide=divide(N)

L=len(divide)

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

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


def main():
    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)
    if len(l)%2 == 0:
        choices = [l[len(l)//2-1], l[len(l)//2]]
        print(choices[0] + choices[1] - 2)
    else:
        print(l[len(l)//2] * 2 - 2)


if __name__ == '__main__':
    main()

Solution (Python):
import math
N=input()
a=0
b=0
c=int(N)
d=math.ceil(math.sqrt(c))
for i in range(1,d+1):
    if(c%i==0):
        a=i
        b=c/i
print(int(a+b-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

a=make_divisors(n=int(input()))
if len(a)%2==0:
    ans=([sum(a[k:k+2]) for k in range(0,len(a),2)])
    print(min(ans)-2)
else:
    print(a[-1]*2-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

divisors=make_divisors(N)

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

Solution (Python):
import math


def resolve():
    N=int(input())
    D=int(math.sqrt(N))
    f=1
    for i in range(1,D+1):
       if N%i==0:
           f=i 
    s=N//f

    print(f+s-2)



if __name__ == "__main__":
    resolve()

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 = min([(a, b) for a, b in zip(divisors, reversed(divisors))], key=lambda x: x[0] + x[1] - 2)
print(ans[0] + ans[1] - 2)

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

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

Solution (Python):
import math

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

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

    return (True, 1)

def solve():
    n = int(input())
    p, k = is_prime(n)
    if p:
        print(n-1)
        return
    l = n // k
    print(k + l - 2)
    return
    '''
    half = int(math.sqrt(n))
    for i in range(half, n):
        if n % i == 0:
            a = i
            b = n // i
            print(a + b - 2)
            return
    return 
    '''

if __name__ == '__main__':
    solve()

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

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

Solution (Python):

import math
def solve(n):
    ans = float('inf')
    for x in range(1, int(math.sqrt(n)) + 3):
        if n % x == 0:
            y = n // x
            ans = min(ans, x + y - 2)
    return ans
print(solve(int(input())))

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

  divisors.sort()
  return divisors
  
n=int(input())
kirisute=math.floor(math.sqrt(n))
arr=make_divisors(n)

for i in arr:
  if kirisute<= i:
    j=n//i
    ans = i+j-2
    print(ans)
    break

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

m = int(n ** 0.5)

for i in range(m + 1)[::-1]:
    if n % i == 0:
        a = n / i
        print(int(i + a -2))
        exit()

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

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

move = N
i = 1
while(i*i <= N):
    rem = N % i
    if rem == 0:
        a = i
        b = int(N/i)
        if move > a+b -2:
            move = a+b-2
            
    i += 1
print(move)

Solution (Python):
n = int(input())
mx = int(10e6+1)
y=0
mn = int(10e13)
for v in range(1,mx):
    if v<=n and n%v==0:
        y=1
        left = n//v
        mn=min(v-1+left-1,mn)
    if v>n:
        break
if y:
    print(mn)
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 + (N // i) - 2)

print(ans)

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

yaku = []

for i in range(1, int(math.sqrt(N))+1):
    if N%i==0:yaku.append([i, N//i])

ab=N
for a, b in yaku:
    ab = min(ab, a+b-2)

print(ab)

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


def main():
    n = int(input())
    divs = make_divisors(n)
    res = divs[0]
    print(res - 2)


if __name__ == '__main__':
    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)
            
            divisors.append(n//i)
                
    return divisors
N = int(input())
tmp = make_divisors(N)
anss = []
for i in range(len(tmp)//2):
    anss.append(tmp[2*i] + tmp[2*i+1])
print(min(anss) - 2)

Solution (Python):

import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7


def make_divisors(n):
    re=inf
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            if i != n // i:
                re=min(re,i+(n//i))
            else:
                re=min(re,i+i)
    return re

n = int(input())
ans = 0
a = make_divisors(n)
print(a-2)

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

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

Solution (Python):
import math

n = int(input())
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)

ans = math.pow(10, 12)
tmp = 0
for i in divisors:
    j = n / i
    tmp = i + j -2
    if tmp < ans:
        ans = tmp

print(int(ans))

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

n = int(N**0.5)
while N%n != 0:
  n -= 1

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

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

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

divisors = make_divisors(n)
x, y = divisors[-1], n // divisors[-1]
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)
            divisors.append(n//i)

    divisors.sort()
    return divisors

a = make_divisors(N)
print(a[len(a)//2-1]-1 +  a[len(a)//2]-1)

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

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


x=int(input())
divisors=make_divisors(x)
sq=int(-(-x**0.5//1))
for i in divisors:
    if i >= sq:
        print(int(x/i)+i-2)
        exit(0)

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+ n//i)
    return divisors
ans = min(make_divisors(N)) -2
print(ans)

Solution (Python):
def make_pairs(n):
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            pairs.append((i, n//i))

N = int(input())
pairs = []
make_pairs(N)

res = N
p = (1, N)
for pair in pairs:
    if res > pair[0]+pair[1]:
        p = (pair[0], pair[1])
        res = pair[0]+pair[1]

if p[0] > 1:
    res -= 1
if p[1] > 1:
    res -= 1

print(res)

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

for i in range(1,N_sqrt+1):
    if N % i == 0:
        x = i
        y = int(N/i)

print(x+y-2)

Solution (Python):

import sys
input = sys.stdin.buffer.readline


from collections import defaultdict

INF = float("inf")

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


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

if __name__ == '__main__':
	main()

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


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

    divisors.sort()
    return divisors


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

Solution (Python):
n = int(input())
i= 1
a = []

while i * i <= n:
  if n % i == 0:
    m = n // i
    a.append(m+i-2)
  i += 1
    
print(min(a))

Solution (Python):

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