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:
n = int(input())
ans = 1e23
for x in range(1,1000000+1):
	if n%x: continue
	y = n//x
	ans = min( ans , y-1 + x-1 )
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import queue

"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

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

Submission status: Accepted

Solution code:
import math

n = int(input())

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

        ans = min(ans,memo1+memo2)

print(ans-2)

Submission status: Accepted

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

ans = float('inf')
for d1, d2 in X:
    ans = min(ans, d1 + d2 - 2)

print(ans)

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())
yakusu=make_divisors(n)
yakusu=sorted(yakusu)
ngs=len(yakusu)
if len(yakusu)%2==0:
    #print(yakusu[int(ngs//2)], yakusu[int(ngs//2)-1])
    print(yakusu[int(ngs//2)]+yakusu[int(ngs//2)-1]-2)
else:
    #print(yakusu[int(ngs//2)])
    print(yakusu[int(ngs//2)]+yakusu[int(ngs//2)]-2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin


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


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


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


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


n = intput()

ff = 100000000000

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

print(dist)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

Solution code:
import sys

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

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

Submission status: Accepted

Solution code:
# 約数のリストを表示する(因数分解ではない)
# make_divisors(16)
# [1, 16, 2, 8, 4]
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

# 約数のリストを表示する(1とその数を除く)
# make_divisors_without_own(16)
# [2, 8, 4]
def make_divisors_without_own(n):
    r = make_divisors(n)
    r.remove(1)
    r.remove(n)
    return r
n = int(input())

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

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
import sys
input = sys.stdin.readline
def solve():
  n = int(input())
  a = make_divisors(n)
  ans = n-1
  for a1 in a:
    a2 = n//a1
    ans = min(ans,a1+a2-2)
  print(ans)
solve()

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

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

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=make_divisors(n)
ans=10**18
for i in l:
    j=n//i
    ans=min(ans,i+j-2)
print(ans)

Submission status: Accepted

Solution code:
from math import sqrt

N = int(input())

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

print(res)

Submission status: Accepted

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

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

N = INT()

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

print(a-1+b-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

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

    # divisors.sort()
    return divisors

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

print(min-2)

Submission status: Accepted

Solution code:
N=int(input())

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

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

Submission status: Accepted

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

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

li=make_divisors(n)

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

Submission status: Accepted

Solution code:

N = int(input())

i = 1
ans = float("inf")

while i ** 2 <= N:

    if N % i == 0:

        j = N // i

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

    i+=1

print (ans)

Submission status: Accepted

Solution code:

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

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

print(ans)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python

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

sys.setrecursionlimit(1000000)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict

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

mod = 10**9 + 7

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

#################

N = I()

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

sys.setrecursionlimit(1000000)
mod = 1000000007

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

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

# 約数の全列挙
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort(reverse=True)  # ソート
    return divisors

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

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

    print(ans)

sol()

Submission status: Accepted

Solution code:
import sys
import math
from collections import Counter

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


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


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


def solve():
    return


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



    print(ans-2)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from math import sqrt
from functools import reduce
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

def lcm(a, b):
    return a*b//gcd(a, b)
n = int(input())
n2 = n
pfs = []
isP = True
i = 2
while i <= int(sqrt(n)):
    while n % i == 0:
        pfs.append(i)
        n //= i
        isP = False
    i += 1
pfs.append(n)
"print (pfs)
if isP:
    ans =  (n2-1)
elif len(pfs) > 2:
    l = reduce(lcm, pfs)
    ans = l-1 + n2//l-1
else:
    ans = pfs[-1]-1 + n2//pfs[-1]-1
print (ans)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
M = []
sqr_N = math.floor(math.sqrt(N))
    
for i in range(sqr_N):
    if i == 0:
        continue
    elif N % i == 0:
        M.append(i)

O = []
ANS = []        
for i in range(len(M)):
    O.append(N // M[i])
    


for i in range(len(O)):


    ANS.append(O[i] + M[i]) 
        
     
        
min = min(ANS)

print(min - 2)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
M = []
sqr_N = math.floor(math.sqrt(N))
    
for i in range(sqr_N):
    if i == 0:
        continue
    elif N % i == 0:
        M.append(i)
        
        
ANS = (max(M) - 1) + ((N / max(M)) - 1)

print(int(ANS))

Submission status: Runtime Error

Solution code:
import sympy

N=int(input())
l=[]
for i in sympy.divisors(N):
    l.append([i,N/i])
L=len(l)
s=[0]*L
for j in range(L):
    s[j]=l[j][0]+l[j][1]
print(int(min(s))-2)

Submission status: Runtime Error

Solution code:
import sympy

def solve():
    N = int(input())
    D = sympy.divisors(N)
    ans = N - 1
    for d in D:
        print(d)
        ans = min(ans, N // d - 1 + d - 1)
    print(ans)

if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
import math
a,b,x = map(int,input().split())
y = (a**2)*b
h = x/(a**2)

def get_angle_from_sides(a, b, c):
    return math.acos((a ** 2 + b ** 2 - c ** 2) / (2 * a * b))

def checkio(a, b, c):
    try:
        angles = [get_angle_from_sides(*abc) for abc in ((a, b, c), (b, c, a), (c, a, b))]
        result = sorted((math.degrees(a)) for a in angles)
        return [0, 0, 0] if 0 in result else result
    except ValueError:
        return [0, 0, 0]
count = 0
if y/2 <=x:
  if a>=2*(b-h):
    m = checkio(a,2*(b-h),math.sqrt(a**2+(2*(b-h))**2))
    count = m[0]
  elif a<2*(b-h):
    m = checkio(a,2*(b-h),math.sqrt(a**2+(2*(b-h))**2))
    count = m[1]
elif y/2>x:
  z = 2*x/(a*b)
  if b>=z:
    m = checkio(b,z,math.sqrt(b**2+(z)**2))
    count = m[1]
  elif b<z:
    m = checkio(b,z,math.sqrt(b**2+(z)**2))
    count = m[0]
#print(a,2*(b-h),math.sqrt(a**2+2*(b-h)**2),m)
print(count)

Submission status: Runtime Error

Solution code:
import math

ans = 1000000000000000000
N = int(input())
for i in range(math.sqrt(N+1000)):
  if i > 0 and N % i == 0:
    ans = min(i + N/i - 2, ans)
print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools as fts
import itertools as its
import math
import sys
import numpy as np

INF = float('inf')


def solve(N: int):
    def manhattan_distance(x1, y1, x2, y2):
        return abs(x1-x2) + abs(y1-y2)
    return min(manhattan_distance(1, 1, i, N//i) for i in range(1, int(math.sqrt(N))+1) if N % i == 0)


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    print(f'{solve(N)}')


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
m = 10**12
a = int((n**0.5)//1)
for i in a:
  if n%i==0:
    m=min(m,i+(n/i)-2)
print(m)

Submission status: Runtime Error

Solution code:
n = int(input())
m = 10**12
a = (n**0.5)//1
for i in a:
  if n%i==0:
    m=min(m,i+(n/i)-2)
print(m)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
m = 10**12
for i in n:
  for j in n:
    if i*j==n:
      m=min(m,i+j-2)
print(m)

Submission status: Runtime Error

Solution code:
n = int(input())
m = 10**12
for i in n:
  for j in n:
    if i*j=n:
      m=min(m,i+j-2)
print(m)

Submission status: Runtime Error

Solution code:
n = int(input())
m = 10**12
for i in n:
  for j in n:
    if i*j==n:
      m=min(m,(i+j-2))
print(m)

Submission status: Runtime Error

Solution code:
n = int(input())
m = []
for i in n:
  for j in n:
    if i*j==n:
      m.append(i+j-2)
print(min(m))

Submission status: Runtime Error

Solution code:
n=int(input())
def eratos(n):
   prime_list =set ()
   num_list=set()
   for i in range(2, int(n**0.5)+1):
       if i not in num_list:
           prime_list.add(i)
           for j in range(i*i, n+1, i):
               num_list.add(j)
   return(prime_list)
print(s)
x=int(n**0.5)
while 1:
    if x in s and n%x==0:
        break
    x-=1
print(x+(n//x)-2)

Submission status: Runtime Error

Solution code:
n=int(input())
import numpy
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

pri_fact=prime_factorize(n)

def prod(x):
    kotae=1
    for i in x:
        kotae*=i
    return kotae

ans=10**12
for i in range(len(pri_fact)):
    ans=min((prod(pri_fact[0:i])-1)+(prod(pri_fact[i:])-1),ans)

print(int(ans))

Submission status: Runtime Error

Solution code:
import sympy
n=int(input())
a=sympy.divisors(n)
b=sorted(a,reverse=True)

c=[]
for i in range(len(a)//2):
    d=a[i]-1+b[i]-1
    c.append(d)

print(min(c))

Submission status: Runtime Error

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


l=list(make_divisors(n))

l.sort()

for i,ll in enumerate(l):
  if i!=len(l)-1 and ll*l[i+1]==n:
    ans=ll+l[i+1]-2
if n==1:
  print(0)
else:
  print(ans)

Submission status: Runtime Error

Solution code:
def get_divisors(n):
    if n < 1:
        return
    i = 1
    while i * i <= n:
        if n % i == 0:
            yield i
            if i * i != n:
                yield round(n / i)
        i = i + 1



n=int(input())


l=list(get_divisors(n))

l.sort()

for i,ll in enumerate(l):
  if i!=len(l)-1 and ll*l[i+1]==n:
    ans=ll+l[i+1]-2
if n==1:
  print(0)
else:
  print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = 0
k = 0
for x in range(exit()):
  for y in range(exit()):
    if n % y == 0 and n % x == 0:
      s = x
      k = y
      exit()
print((s - 1) + (k - 1)

Submission status: Runtime Error

Solution code:
#nの約数を列挙する関数
def n_div(n):
    div_list = []
    import math
    for i in range(1, math.ceil(math.sqrt(n))+1):
        if n % i ==0:
            div_list.append(i)
            if i*i ==n:
                continue
            div_list.append(n//i)
    div_list.sort()
    return div_list

n = int(input())
lr = n_div(n)
#print(lr)
if len(lr) % 2==0:
    a = len(lr)/2
    a = int(a)
    ans = lr[a]+lr[a-1]-2
else:
    a = math.floor(len(lr)/2)
    #print(a)
    ans = lr[a]*2  -2
    
print(ans)

Submission status: Runtime Error

Solution code:
#nの約数を列挙する関数
def n_div(n):
    div_list = []
    import math
    for i in range(1, math.ceil(math.sqrt(n))+1):
        if n % i ==0:
            div_list.append(i)
            if i*i ==n:
                continue
            div_list.append(n//i)
    div_list.sort()
    return div_list

n = int(input())
lr = n_div(n)
#print(lr)
if len(lr) % 2==0:
    a = len(lr)/2
    a = int(a)
    ans = lr[a]+lr[a-1]-2
else:
    a = math.floor(len(lr))
    ans = lr[a]**2
    
print(ans)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
s = 0
if N % 2 == 0:
  s = 2 + N // 2

for i in range(3, int(math.sqrt(N), 2):
  if N % i == 0 and s > i + N // i:
    s = i + N // i

print(s-2)

Submission status: Runtime Error

Solution code:
import sympy
N = int(input())

ans = sympy.divisors(N)
x = ans[int(len(ans)/2)-1]
y = ans[int(len(ans)/2)]

print((x-1)+(y-1))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())

n_sq = N ** 0.5

n_sq_int = int(n_sq // 1)

#print(n_sq_int)

for i in reversed(range(n_sq_int)):
    if N % i == 0:
        ans = N // i
        print(ans + i - 2)
        exit()

Submission status: Runtime Error

Solution code:
import sympy

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

Submission status: Runtime Error

Solution code:
import bisect,collections,copy,heapq,itertools,math,string,sympy
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()
c = sympy.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)

#H,N = LI()
#AB = [LI() for _ in range(N)]
#A,B = zip(*AB)
#Ap = np.array(A)
#C = np.zeros(N + 1)

# if ans:
#     print('Yes')
# else:
#     print('No')

Submission status: Runtime Error

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


n = int(input())
low, up = make_divisors(n)
if len(low) != 1:
    ans = low[0] + up[0]
    for i in range(1, len(low)):
        tmp = low[i] + up[i]
        if tmp < ans:
            ans = tmp
    print(tmp - 2)
else:
    print(n - 1)

Submission status: Runtime Error

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


n = int(input())
low, up = make_divisors(n)
if up:
    ans = low[0] + up[0]
    for i in range(1, len(low)):
        tmp = low[i] + up[i]
        if tmp < ans:
            ans = tmp
    print(tmp - 2)
else:
    print(n - 1)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

N = int(input())

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
zimport numpy
n = int(input())
l = []

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
            l.append(a+b-2)
    print(min(l))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
C:\pycharm\code_atcoder\venv\Scripts\python.exe C:/pycharm/code_atcoder/144C.py
100019
100018

プロセスは終了コード 0 で完了しました

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())

steps = []

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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