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: 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:
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 = 1000000

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

print(ans)

Submission status: Runtime Error

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

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

print(ans)

Submission status: Runtime Error

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

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

print(ans)

Submission status: Runtime Error

Solution code:
import sympy
N = int(input())
al = sympy.divisors(N)
L = len(al)
if L%2==1:
    a = al[L//2]
    print((a-1)*(a-1))
else :
    a = al[L//2-1]
    b = al[L//2]
    print(a+b-2)

Submission status: Runtime Error

Solution code:
n=int(input())

div1 = 1
div2 = n
result = 10**12
if n == 1:
  print('0')
  exit()

for i in range(1,int(-(-n**0.5//1))+1):
  if n % i == 0:
    div1 *= i
    div2 /= i
    div_sum = div1 + div2
    result = min(result, div_sum)
print(int(result-2))

Submission status: Runtime Error

Solution code:
n=int(input())

div1 = 1
div2 = n
result = 10**12
if n == 1:
  print('0')
  exit()

for i in range(1,int(-(-n**0.5//1))+1):
  if n % i == 0:
    div1 *= i
    div2 /= i
    div_sum = div1 + div2
    result = min(result, div_sum)
print(int(div_sum-2))

Submission status: Runtime Error

Solution code:
n=int(input())

div1 = 1
div2 = n
result = 10*10
if n == 1:
  print('0')
  exit()

for i in range(1,int(-(-n**0.5//1))+1):
  if n % i == 0:
    div1 *= i
    div2 /= i
    div_sum = div1 + div2
    result = min(result, div_sum)
print(int(div_sum-2))

Submission status: Runtime Error

Solution code:
n=int(input())

div1 = 1
div2 = n
result = 10*10
for i in range(1,int(n**0.5+1)):
  if n % i == 0:
    div1 *= i
    div2 /= i
    div_sum = div1 + div2
    result = min(result, div_sum)
print(int(div_sum-2))

Submission status: Runtime Error

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

print(N/i + i -2)

Submission status: Runtime Error

Solution code:
from math import sqrt
N = int(input()) # 2 <= N <= 10^12
# (1,1) (x,y) = x*y
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)

Submission status: Runtime Error

Solution code:
N=int(input())

a=1
b=N//a
dis=abs(a-b)

for i in range(int(N**0.5)+1):
    if N%i==0:
        _a=i
        _b=N/i
        _dis=abs(_a-_b)
        if _dis<dis:
            a=_a
            b=_b
            dis=_dis

print(a-1+b-1)

Submission status: Runtime Error

Solution code:

#素因数分解
def prime_factorization(N):
    n=N
    a=2
    prime_factor=[]
    while a**2<=n:
        while n%a==0:
            prime_factor.append(a)
            n//=a
        a+=1
    if n>1:
        prime_factor.append(n)
    return prime_factor


# N=100
N=int(input())

a=1
b=N//a
dis=abs(a-b)

Li=prime_factorization(N)
# print(Li)

for p in range(2**len(Li)):
    bit=[]
    for e in range(len(Li)):
        if (p>>e)&1==1:
            bit.append(1)
        else:
            bit.append(0)
    # print(bit)
        proindex=[]
        for _ in range(len(bit)):
            if bit[_] ==1:
                proindex.append(_)
        _a=1
        for j in range(len(Li)**0.5):
            if proindex.count(j)==1:
                _a*=Li[j]
        _b=N//_a
        _dis=abs(_a-_b)
        if _dis<dis:
            a=_a
            b=_b
            dis=_dis
# print(a,b)

print(a-1+b-1)

Submission status: Runtime Error

Solution code:

#素因数分解
def prime_factorization(N):
    n=N
    a=2
    prime_factor=[]
    while a**2<=n:
        while n%a==0:
            prime_factor.append(a)
            n//=a
        a+=1
    if n>1:
        prime_factor.append(n)
    return prime_factor


# N=100
N=int(input())

a=1
b=N//a
dis=abs(a-b)

Li=prime_factorization(N)
# print(Li)

if len(Li)>=6:
    math.random()
    


for p in range(2**len(Li)):
    bit=[]
    for e in range(len(Li)):
        if (p>>e)&1==1:
            bit.append(1)
        else:
            bit.append(0)
    # print(bit)
        proindex=[]
        for _ in range(len(bit)):
            if bit[_] ==1:
                proindex.append(_)
        _a=1
        for j in range(len(Li)):
            if proindex.count(j)==1:
                _a*=Li[j]
        _b=N//_a
        _dis=abs(_a-_b)
        if _dis<dis:
            a=_a
            b=_b
            dis=_dis
# print(a,b)


print(a-1+b-1)

Submission status: Runtime Error

Solution code:
N=int(input())
cnt=N-1
for i in range(1,N):
    if N%i==o:
        cnt=min(cnt,N//i+i-2)
print(cnt)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import math
N = int(input())

def divisor(N):
    lst = []
    for i in range(2,math.ceil(math.sqrt(N))+1):
        if N%i == 0:
            lst.append(i)
            #if i != int(N/i):
                #lst.append(int(N/i))
    #lst.sort()
    return lst
    
ans = divisor(N)
#print(ans,len(ans))
if len(ans) > 0:
    A = ans[-1]
else:
    print(N-1)
if A*A < N:
    B = int(N/A)
    print(A+B-2)
else:
    print(2*A-2)
'''
if len(ans)%2 == 0 and len(ans)>1:
    A = ans[len(ans)//2-1]
    B = ans[len(ans)//2]
    #print(A,B)
    print(A+B-2)
elif len(ans)%2 == 1 and len(ans)>1:
    A = ans[len(ans)//2]
    print(2*A-2)
else:
    print(N-1)
'''

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import math
N = int(input())

def divisor(N):
    lst = []
    for i in range(2,math.ceil(math.sqrt(N))+1):
        if N%i == 0:
            lst.append(i)
            if i != int(N/i):
                lst.append(int(N/i))
    lst.sort()
    return lst
    
ans = divisor(N)
#print(ans,len(ans))
A = ans[len(ans)//2-1]
B = ans[len(ans)//2]
#print(A,B,A*B)
if A*B == N and len(ans)>1:
    print(A+B-2)
elif B**2 == N and len(ans)>1:
    print(2*B-2)
else:
    print(N-1)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import math
N = int(input())

def divisor(N):
    lst = []
    for i in range(2,math.ceil(math.sqrt(N))):
        if N%i == 0:
            lst.append(i)
            
    return lst[-1]
    
def isPrime(n):
  if n == 2:
    return True
  if n % 2 == 0:
    return False
  m = math.floor(math.sqrt(n)) + 1
  for p in range(3, m, 2):
      if n % p == 0:
        return False
  return True
  
if isPrime(N):
    print(N-1)
else:
    ans = divisor(N)
    A = ans
    B = N/ans
    print(int(A+B-2))#
#print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
r=100000000000000000000000000000
for i in range(1,int(pow(n,0.5))+1):
  if(n%i==0):
    r=min(r,abs(i-1)+abs(n//i-1))
print(r(

Submission status: Runtime Error

Solution code:
import math

n = int(input())

t = int(math.sqrt(n))

ans = 0

for i in reversed(range(t)):
    if n % i == 0:
        ans = n//i+i
        break
        
print(ans-2)

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[::-1]

N=int(input())
div=make_divisors(N)

from math import sqrt

tmpmin=10*10
for i in range(len(div)):
  if tmpmin>abs(sqrt(N)-div[i]):
    tmpmin=abs(sqrt(N)-div[i])
    minidx=i

a=div[minidx]
b=N//a

print(a-1+b-1)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
mn=n
for i in range(n):
  if n%i==0:
    j=n//i
    mn=min(mn,i+j)
print(mn)

Submission status: Runtime Error

Solution code:
import math
import numpy as np

n = int(input())
n_2 = int(math.sqrt(n + 1))   
div = x[n % x == 0]
ans = 10 ** 12
for i in div:
    j = (n // i) + i - 2
    ans = min(ans, j)
print(ans)

Submission status: Runtime Error

Solution code:
import math
N=int(input())
sqn=math.floor(math.sqrt(N))

for fac in reversed(range(sqn)):
    if N%fac==0:
        print(int(fac+N/fac-2))
        break

Submission status: Runtime Error

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

A=[]

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

Submission status: Runtime Error

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



A=[]

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

Submission status: Runtime Error

Solution code:
import sys
from collections import deque
N=int(input())
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
S=deque(sorted(prime_factorize(N)))
if len(S)==1:
    print(sum(S)-1)
    sys.exit()
while len(S)>2:
    x=S.popleft()
    y=S.popleft()
    S.append(x*y)
    S=sorted(S)
print(sum(S)-2)

Submission status: Runtime Error

Solution code:
n = int(input())

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

Submission status: Runtime Error

Solution code:
n = int(input())

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

N = int(input())
b = n**0.5//1.0
while True:
    if N%b != 0:
        b -= 1
    else:
        break
print(int(b+N/b-2))

Submission status: Runtime Error

Solution code:
import numpy as np

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

N = int(input())
A = prime_factorize(N)

n = len(A)
ans = []
for i in range(1,2**n-1):
    a = [1]
    b = [1]
    for j in range(n):
        if (i >> j) & 1:
            a.append(A[j])
        else:
            b.append(A[j])
    ap, bp = np.prod(a), np.prod(b)
    ans.append(bp+ap)
print(min(ans)-2)

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

def walk_on_multiplication_table(n):

    ans = 10**13
    yaku = make_divisors(n)
    yaku.sort()
    count = len(yaku)

    for i in range(int(count//2)):
        ans = min(ans, (yaku[i]+yaku[count-i-1]-2))

    if count % 2 == 0:
        return ans

    return min(ans, (yaku[int((count+1)**2)]-2))

def main():
    n = int(input())
    print(walk_on_multiplication_table(n))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sympy
sympy.divisors(10**9)

n = int(input())
L = len(sympy.divisors(n))
i,j = sympy.divisors(n)[L//2-1], sympy.divisors(n)[L//2]

if (n**0.5).is_integer():
    print(int(2*(n**0.5-1)))
else:
    print(i+j-2)

Submission status: Runtime Error

Solution code:
import itertools

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

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

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

    return arr  
N = int(input())
_max = 0
for pair in itertools.combinations(factorization(N),2):
    print(itertools.combinations(factorization(N),2))
    print(pair)
    _max = max(pair[0]+pair[1],_max)
print(_max-2)

Submission status: Runtime Error

Solution code:
import sys
n = int(input())
ans = 10**12

for k in range(1,(n+1)**0.5):
    if n%k == 0 :
        m = n//k + k - 2
        if ans > m:
            ans = m
        else:
            print(ans)
            sys.exit()
print(ans)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

using namespace std;

int main(){

	long long int n, lim,res=2;
	cin >> n;
	res=n;
	lim = sqrt(n);

	for(int i=1;i<=lim;i++){
		if(n%i==0){
			if(i+n/i -2<res)
				res = i + n/i -2;
		}
	}

	cout << res << endl;

	return 0;
}

Submission status: Runtime Error

Solution code:
N = int(input())
import math
n = int(math.sqrt(N))
s = 0
for i in range(1,n):
  if N%i == 0 and i > s:
    s = i
    
p = int(s+N/s-2)
print(p)

Submission status: Runtime Error

Solution code:
# C - Welcome to AtCoder
# https://atcoder.jp/contests/abc151/tasks/abc151_c

n,m = map(int,input().split())
submits = [list(input().split()) for i in range(0,m)]

ac = 0
wa = 0

AC = "AC"
WA = "WA"

tmp_wa = 0
tmp_ac = []


for i in range(len(submits)):
    # ACなら正解数をカウントアップ
    if submits[i][1] == AC:
        # 同じ問題に正解してないかチェック
        if submits[i] in tmp_ac:
            # tmp_ac = submits[i]
            continue
        ac += 1
        # WAの数をカウント
        wa += tmp_wa
        # WAを初期化
        tmp_wa = 0
        tmp_ac.append(submits[i])
    else:
        # WAならwa+1
        tmp_wa += 1

print(str(ac) + " " + str(wa))

Submission status: Runtime Error

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

print(min(can))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#ABC 144 C - Walk on Multiplication Table
N = int(input())

import math 
def get_prime(n):
    
    if n <=1:
        return []
    prime = [2]
    limit = int(math.sqrt(n))
    
    # 奇数のリストを作成
    data = [i+1 for i in range(2,n,2)]
    while limit > data[0]:
        prime.append(data[0])
        data = [j for j in data if j % data[0] !=0]
    return prime + data
from itertools import combinations
import functools
import operator
P = get_prime(N)
m = N+1
memo = []
for i in range(1,len(P)+1):
    L1 = list(combinations(P,i))
    L1 = [list(l) for l in L1]
    for l in L1:
        if l not in memo:
            memo.append(l)
            s1 = functools.reduce(operator.mul,l)
            s2 = N/s1
            if s1+s2 <=m:
                m = s1+s2
print(int(m-2))

Submission status: Runtime Error

Solution code:
import math
N = int(input())
factors = []

while N % 2 == 0:
    factors.append(2)
    N //= 2
f = 3
while f*f <= N:
    if N % f == 0:
        factors.append(f)
        N //= f
    else:
        f += 2

if not factors:
    print(N-1)
else:
    if N > 1:
        factors.append(N)

    n = len(factors)
    sums = []
    for i in range(1, n**2-1):
        l = 1
        r = 1
        for j in range(n):
            if (i >> j) & 1:
                l *= factors[j]
            else:
                r *= factors[j]
        sums.append(l-1 + r-1)
    print(min(sums))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())

list=[]

for i in range(1,int((n+1)/2)):
    a=n%i
    if(len(list) == 1 and i>n/i):
        ans=(list[-1][0]-1)+(list[-1][1]-1)    
        break
    if a == 0:
        if(i<n/i):
            list.append([i,int(n/i)])
        else:
            list.append([int(n/i),i])
            if len(list) == 1:
                ans=(list[-1][0]-1)+(list[-1][1]-1)
                break
            if list[-1]==list[-2]:
                ans=(list[-1][0]-1)+(list[-1][1]-1)
                break
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())

list=[]

for i in range(1,int(n+1/2)):
    a=n%i
    if a == 0:
        if(i<n/i):
            list.append([i,int(n/i)])
        else:
            list.append([int(n/i),i])
            if len(list) == 1:
                ans=(list[-1][0]-1)+(list[-1][1]-1)
                break
            if list[-1]==list[-2]:
                ans=(list[-1][0]-1)+(list[-1][1]-1)
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())

list=[]

for i in range(1,12):
    a=n%i
    if a == 0:
        if(i<n/i):
            list.append([i,int(n/i)])
        else:
            list.append([int(n/i),i])

    if i>1 :
        if len(list) == 1:
            ans=(list[-1][0]-1)+(list[-1][1]-1)
            break
        if list[-1]==list[-2] or len(list)==1:
            ans=(list[-1][0]-1)+(list[-1][1]-1)
            break
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

maximum = math.ceil(math.sqrt(n))
minimum = 10**20
for i in range(1,maximum):
    j = 0
    if n % i == 0:
        j = n / i
        minimum = min(minimum,i+j)

print(int(minimum-2))

Submission status: Runtime Error

Solution code:
import math

N = int(input())

for i in reversed(range(int(math.sqrt(N)))):
    if N % i == 0:
        print(i + N//i - 2)
        exit()

Submission status: Runtime Error

Solution code:
n=int(input())
r=n**(1/2)
w=0
for i in range(1,int(r)+1):
  if n%i==0:
    w=i
x,y=w,n//w
print(x+y-1 if x=1 or y=1 else x+y-2)

Submission status: Runtime Error

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')



n = I()
sqrtn = sqrt(n)
for i in reversed(range(floor(sqrtn))):
    if n % i == 0:
        a = int(n/i)
        print(a+i-2)
        exit()

Submission status: Runtime Error

Solution code:
### ----------------
### ここから
### ----------------

import sys
import math
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n=int(readline())

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

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())

for i in range(int(N**0.5), 1, -1):
    if (N / i).is_integer():
        a = N // i
        b = N // a
        break

print(a+b-2)

Submission status: Runtime Error

Solution code:
import math

def main():
    n = int(input())
    m = math.sqrt(n)
    m = int(m) if float.is_integer(m) else math.floor(m) - 1
    div = n // m
    # print(m, div)
    print(m-1 + div-1)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())

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

Submission status: Runtime Error

Solution code:
import math as m

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

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

print(int(k+l-2))

Submission status: Runtime Error

Solution code:
from collections import deque
from math import sqrt

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

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

print(min(step))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import math
import numpy as np

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

Submission status: Runtime Error

Solution code:
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)
i = 0
div = make_divisors(n)
div.sort()
while True:
    if div[i]*div[i+1] == n:
        print(div[i]+div[i+1]-2)
        break
    elif div[i]*div[i] == n:
        print(div[i]+div[i]-2)
        break     
    else:
        i += 1

Submission status: Runtime Error

Solution code:
import os

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


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

    return divisors

	
if __name__ == "__main__":
	main()

Submission status: Runtime Error

Solution code:
def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())

N = intinp()

d = []
m = []
for i in range(1, N//4):
    if i in d:
        break
    if N%i == 0:
        d.append(i)
        d.append(N//i) 
        m.append(i+N//i-2)

print(min(m))

Submission status: Runtime Error

Solution code:
def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())

N = intinp()

d = []
m = []
for i in range(1, N//2):
    if i in d:
        break
    if N%i == 0:
        d.append(i)
        d.append(N//i) 
        m.append(i+N//i-2)

print(min(m))

Submission status: Runtime Error

Solution code:
def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())

N = intinp()

d = []
m = []
for i in range(1, N//2):
    if i in d:
        continue
    if N%i == 0:
        d.append(i) 
        m.append(i+N//i-2)

print(min(m))

Submission status: Runtime Error

Solution code:
n = int(input())

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

print(cnt + n//cnt - 2)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
min_ = n -1 
for i in range(1, n**0.5+10):
  if n % i != 0:
    continue
  else:
    min_ = min(min_, i-1+n//i-1)
    
print(min_)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
n = int(input())
m = n**0.5
ans = 0
#print(n)
#print(m)
for i in range(1,math.floor(m+1)):
    if m%i==0:
        ans = i
print(math.floor(ans+ n/ans -2))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import math
import fractions
import sys
import itertools
import numpy as np
from collections import Counter
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

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



n=input1()

for i in range(int(math.sqrt(n)) +1,-1,-1):
	if n%i==0: #iがnの約数
		print((i-1) + (n//i -1))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())

factor_a = 0
for i in reversed(range(1, int(np.sqrt(n)))):
    if n % i == 0:
       factor_a = i
       break

factor_b = n // factor_a

print(factor_a - 1 + factor_b - 1)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
ran = math.floor(math.sqrt(N))
max = 0
for i in range(１、ran):
    if N%i == 0:
        if i > max:
            max = i
print(i + N/i -2)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
a = 1
b = 1
ran = math.floor(math.sqrt(N))
max = 0
for i in range(ran):
    if N%i == 0:
        if i > max:
            max = i
print(i + N/i -2)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
n=int(input())
li=[]
for x in range(2,int(math.sqrt(n))+1):
    if n%x==0:
        y=n//x
        walk=y+x-2
        li.append(walk)
    
if li==[]:
    print(n-1)
else:
    print(min(li))
import math
n=int(input())
li=[]
for x in range(2,int(math.sqrt(n))+1):
    if n%x==0:
        y=n//x
        walk=y+x-2
        li.append(walk)
    
if li==[]:
    print(n-1)
else:
    print(min(li))

Submission status: Runtime Error

Solution code:
import itertools
import math
n = int(input())
lis1 = []
for i in range(n):
    lis1.append(list(map(int, input().split())))
S = 0
for i in list(itertools.permutations(range(n))):
    for j in range(n-1):
        S += math.sqrt((lis1[i[j]][0]-lis1[i[j+1]][0])**2 + (lis1[i[j]][1]-lis1[i[j+1]][1])**2)
for i in range(1, n+1):
    S = S / i
print(S)