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.



Sample input:
10


Sample output:
5

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from heapq import heappush, heappop
from math import sqrt
#input = sys.stdin.readline
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)
    #print(div, div[len(div)//2 - 1])
    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)

Submission status: Accepted

Solution code:
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_)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

# print(make_divisors(N))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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())))

Submission status: Accepted

Solution code:
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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        # print(i)
        if n % i == 0:
            divisors.append(i)
            # if i != n // i:
            divisors.append(n//i)
                # print(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)
# print(tmp)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#設定
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# abc144_c
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)

Submission status: Accepted

Solution code:
import math

def factor(n):
    r = []
    tmp = n
    for i in range(2, int(math.sqrt(n)) + 1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            r.append((i, cnt))
    if tmp != 1:
        r.append((tmp, 1))
    if not r:
        r.append((n, 1))
    return r

def all_pat(l):
    k = [0] * len(l) 
    t = [tuple(k)]
    while True:
        k[0] += 1
        for i in range(len(l)):
            if k[i] <= l[i][1]:
                break
            k[i] = 0
            if i == len(l) - 1:
                return t
            k[i + 1] += 1
        t.append(tuple(k))
    

def main():
    a = int(input())
    l = factor(a)
    p = all_pat(l)
    t = []
    for i in p:
        m = 1
        for j in range(len(l)):
            m *= l[j][0] ** i[j]
        t.append(m + (a // m))
    print(min(t) - 2)
            


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
import math


def solve(*args: str) -> str:
    n = int(args[0])

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


if __name__ == "__main__":
    print(solve(*[input() for _ in range(1)]))

Submission status: Accepted

Solution code:
import math

n = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
import math
def devision(N):
    i = int(math.sqrt(N))
    a = list()
    for j in range(1,i+1):
        if N % j == 0:
            a.append(j)
    return a[len(a)-1]
def move(N):
    return (devision(N) + N//devision(N) - 2)
print(move(N))

Submission status: Accepted

Solution code:
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)
#print(divisors)
minval = 10**15

if len(divisors)%2 == 0:
    #print("hoge")
    for i in range(len(divisors)//2):
        a,b = divisors[i],divisors[len(divisors)-1-i]
        if (a+b)<minval:
            minval = a+b
            
if len(divisors)%2 == 1:
    for i in range(len(divisors)//2+1):
        if i ==len(divisors)//2:
            a,b = divisors[i],divisors[i]
        else:
            a,b = divisors[i],divisors[len(divisors)-1-i]
        #print(a,b)
        if (a+b)<minval:
            minval = a+b
print(minval-2)

Submission status: Accepted

Solution code:
N = int(input())

ret = [1, N]
for i in range(1,N):
    if i > N // i:
        break
        
    if N % i == 0:
        ret = [i, N // i]

print(ret[0] + ret[1] - 2)

Submission status: Accepted

Solution code:
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())
li = make_divisors(n)

ans = 10 ** 12
for i in li:
    j = n // i
    tmp_ans = (i-1)+(j-1)
    if tmp_ans < ans:
        ans = tmp_ans
print(ans)

Submission status: Accepted

Solution code:
# 2つの入力を空白で分割し、数値化
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

yakusu_list = make_divisors(N)
#print(yakusu_list)
mid = yakusu_list[len(yakusu_list) // 2]

mid2 = N // mid

print((mid - 1) + (mid2 - 1))