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:
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))):
#     print(i, type(i))
    for j in range(n-1):
#         print(lis1[i[j]][0], lis1[i[j+1]][0])
        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)

Submission status: Runtime Error

Solution code:
n = int(input())
lis = []
for i in range(n):
    lis.append(list(map(int, input().split())))
s = 0
for i in range(n):
    for j in range(i,n):
        s += ((lis[i][0] - lis[j][0])**2 + (lis[i][1] - lis[j][1])**2)**(1/2)
print(s*2/n)

Submission status: Runtime Error

Solution code:
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial, log, log10, log2
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  n = int(readline())
  x = [0] *n
  y = [0]*n
  for i in range(n):
    x[i], y[i] = map(int, readline().split())
  dis = [[0 for i in range(n)]for j in range(n)]
  total = 0
  for i in range(n):
    for j in range(i+1,n):
      total += 2*((x[i]-x[j])**2+(y[i]-y[j])**2)**0.5
  print(total/n)
  
  
  
  
if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
n = int(input())
divisors = []
for i in range(1, int(pow(n, 0.5)) + 1):
    if n % i == 0:
        if i != n // i:
            divisors.append([i, n // i])
        else:
            divisors.append([i])
divisors = sorted(divisors, key= lambda x:x[1])
res = divisors[0][0] - 1 + divisors[0][1] - 1
print(res)

Submission status: Runtime Error

Solution code:
n=int(input())
c=10**9
for i in range(1,n**0.5):
    if n%i==0:
        j=n/i
        if i+j < c:
            c=int(i+j)

print(c-2)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())

List = []
for i in range(1,10*5):
    for j in range(1,10**5):
        if N == i*j:
            List.append(i+j)

print(min(List)-2)

Submission status: Runtime Error

Solution code:
import math
n=int(input())
lst=[]
up=math.ceiling(math.sqrt(n))-1
for i in range(1,up+1):
    if i**2>n:
        break
    if n%i==0:
        lst.append(i+n//i)
print(min(lst)-2)

Submission status: Runtime Error

Solution code:
num = int(input())
list = []
a = round(num/2)

for i in range(1,int(a)):
    if num % i == 0:
        list.append((i-1)+(num/i)-1)
    else:
        None

list.sort()
print(round(list[0]))

Submission status: Runtime Error

Solution code:
num = int(input())
list = []
a = round(num+1)/2

for i in range(1,int(a)):
    if num % i == 0:
        list.append((i-1)+(num/i)-1)
    else:
        None

list.sort()
print(round(list[0]))

Submission status: Runtime Error

Solution code:
a = int(input())
c = [j for j in range(1,int(a**0.5)) if a%j==0]
print((max(c)-1) + (a//max(c)-1))

Submission status: Runtime Error

Solution code:
n = int(input())
ans = 0
for i in range(int(n**0.5)):
  if n%i == 0:
    l = i + (n/i) -2 #-2は(0,0)->(1,1)の分
    ans = min(ans, l)
print(ans)

'''
10^12 以下の 正整数 N が与えられます。
この整数を i×j (i,j∈N) と表したとき，i+j−2 の最小値を求める問題です。
まず，愚直に考えると [1, N] の範囲で 2 重ループを回し，ij=N となる 2 整数の和の最小値を更新すればよいです。しかし，これは O(N2) となり，到底間に合いません。
ここで，約数 (つまり，ij=N, i≤j となる i,j すべて) を列挙する際，一方の約数 i は N−−√ 以下であることを利用します。もう一方の約数 j は N÷i から求まるので，すべての約数は O(N−−√) で求まることがわかります。
あとは，すべての i,j の組を列挙し，i+j−2 の最小値を求めれば良いです。1×N=N であることは自明なので，1+N–2=N–1 を初期値にしておきましょう。

計算量 O(N−−√)
'''

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input());print(min(x+n/x-2for x in range(1,int(n**.5)+1)if n%x<0))

Submission status: Runtime Error

Solution code:
import math
N=int(input())
list=[]#素因数の格納
for i in range(1,int(math.sqrt(N))):
    if N//i==N/i:
        list.append(N//i+i)
print(min(list)-2)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 10 21:05:26 2020

@author: Kanaru Sato
"""

import math

n = int(input())
rootn = int(math.sqrt(n))

list = []

for i in range(1, rootn):
    if n%i ==0:
        list.append([i,n//i])

dist = list[-1][0]+list[-1][1]-2

print(dist)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 10 21:05:26 2020

@author: Kanaru Sato
"""

import math

n = int(input())
rootn = int(math.sqrt(n))

list = []

for i in range(1, rootn):
    if n%i ==0:
        list.append([i,n//i])

min = n-1

for i in range(0,len(list)):
    dist = list[i][0]+list[i][1]-2
    if dist <= min:
        min = dist

print(dist)

Submission status: Runtime Error

Solution code:
import math

n = int(input())
tmp_list = []

for i in range(1, int(math.sqrt(n)), 1):
    if(n%i==0):
        tmp_list.append(i)

i = tmp_list[len(tmp_list)-1]
j = n//i

print(i+j-2)

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())

U = np.arange(1, n, dtype = np.int64)

div = U[n % U == 0]

ans = min((n / div) + div) - 2

print(int(ans))

"""
from itertools import combinations
import numpy as np

n = int(input())

a = 2
cnt = 0
ans = []


def walk_counter(ll, n):
    left = np.prod(ll)
    right = n // left
    return left + right - 2


tmp_n = n

while tmp_n >= a:
    while tmp_n % a == 0:
        tmp_n = tmp_n // a
        # cnt += 1
        ans.append(a)
    # if cnt > 0:
    #     ans.append([a, cnt])
    #     cnt = 0
    a = a + 1

if tmp_n == a:
    ans.append(a)

fin = 0

for i in range(len(ans)):
    for v in combinations(ans, i):
        tmp = walk_counter(v, n)
        if i == 0:
            fin = tmp
        elif fin > tmp:
            fin = tmp

# 組み合わせでなく、√nまでの試し割法のほうが早い

print(fin)
"""

Submission status: Runtime Error

Solution code:
n = int(input())
ls = make_divisors(n)
pairs = []
for i in ls:
    pair = (i, n//i)
    pairs.append(pair)
count = []
for pair in pairs:
    count.append(pair[0] + pair[1] - 2)
print(min(count))

Submission status: Runtime Error

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

list_n = make_divisors(n)

a = len(list_n)
ans = []
for i in range(0, a, 2):
    ans.append(list_n[i]+list_n[i+1])

ans.sort()

print(ans[0]-2)

Submission status: Runtime Error

Solution code:
import sys
import fractions


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    m = 0
    for i in range(2, int(n ** 0.5) + 1):
        m = max(m, fractions.gcd(n, i))
    print(n // m + m - 2)


if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
import math

N = int(input())

ans = 10**13


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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import collections
import itertools
from operator import mul

n = int(input())
k = n
ans = n -1
prime = []

while k != 1:
    for i in range(2,int(k**0.5)+1):
        if k % i == 0:
            prime.append(i)
            k /= i
            break
    else:
        prime.append(int(k))
        k = 1

div = list(itertools.accumulate(prime,mul))

for i in div:
    ans = min(ans,i + n//i -2)

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
#n=i*jを満たすi,jで，i+jが最小

lis=prime_factorize(n)
lis.sort()
lis_a=[lis[i] for i in range(len(lis)) if i%2==0]
lis_b=[lis[i] for i in range(len(lis)) if i%2!=0]
print(product(lis_a)+product(lis_b)-2)

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
  
def product(lis):
    res=1
    for i in range(len(lis)):
        res*=lis[i]
    return res

Submission status: Runtime Error

Solution code:
n = int(input())

for i in range(2,int(n**(1/2)+1)):
    divisor_lst = []
    if n%i==0:
        j = n//i
        divisor_lst.append([i,j])

n_x = divisor_lst[-1][0]
n_y = divisor_lst[-1][1]

print(n_x+n_y-2)

Submission status: Runtime Error

Solution code:
def prime_number(x):
    if x==2 or x==3:
        return True
    else:
        if x&2==0 or x%3==0:
            return False
        else:
            divisor_lst = [1,x]
            for i in range(1,x+1):
                if i%2!=0 and i%3!=0:
                    if i not in divisor_lst and x%i==0:
                        return False
                    break
            else:
                return True

n = int(input())

if prime_number(n):
    print(n-1)
else:
    i = 1
    j = n//i
    divisor_lst = []
    while i<=j:
        i += 1
        j = n//i
        if n%i==0:
            divisor_lst.append([i,j])

    n_x = divisor_lst[-1][0]
    n_y = divisor_lst[-1][1]
    print(n_x+n_y-2)

Submission status: Runtime Error

Solution code:
def prime_number(x):
    if x==2 or x==3:
        return True
    else:
        if x&2==0 or x%3==0:
            return False
        else:
            divisor_lst = [1,x]
            for i in range(1,x+1):
                if i%2!=0 and i%3!=0:
                    if i not in divisor_lst and x%i==0:
                        return False
                        break
            else:
                return True

n = int(input())

if prime_number(n):
    print(n-1)
else:
    i = 1
    j = n//i
    divisor_lst = []
    while i<=j:
        i += 1
        j = n//i
        if n%i==0:
            divisor_lst.append([i,j])

    n_x = divisor_lst[-1][0]
    n_y = divisor_lst[-1][1]
    print(n_x+n_y-2)

Submission status: Runtime Error

Solution code:
def prime_number(x):
    divisor_lst = [1,x]
    for i in range(1,x+1):
        if i not in divisor_lst and x%i==0:
            return False
        break
    else:
        return True

n = int(input())

if prime_number(n):
    print(n-1)
else:
    i = 1
    j = n//i
    divisor_lst = []
    while i<=j:
        i += 1
        j = n//i
        if n%i==0:
            divisor_lst.append([i,j])

    n_x = divisor_lst[-1][0]
    n_y = divisor_lst[-1][1]
    print(n_x+n_y-2)

Submission status: Runtime Error

Solution code:
def prime_number(x):
    if x==2 or x==3:
        return True
    else:
        if x%2==0 or x%3==0:
            return False
        else:
            divisor_lst = [1,x]
            for i in range(1,x+1):
                if i not in divisor_lst and x%i==0:
                    return False
                    break
            else:
                return True

n = int(input())

if prime_number(n):
    print(n-1)
else:
    i = 1
    divisor_lst = []
    while i<=j:
        i += 1
        j = n//i
        if n%i==0:
            divisor_lst.append([i,j])

    n_x = divisor_lst[-1][0]
    n_y = divisor_lst[-1][1]
    print(n_x+n_y-2)

Submission status: Runtime Error

Solution code:
N = int(input())
dp = []
dp[0] = 0
i = 1
j = 1
for k in range(1,N):
  dp[k] = max(i+1*j,i*j+1)
  if max(i+1*j,i*j+1) == i+1*j:
    i += 1
  elif max(i+1*j,i*j+1) == i*j+1:
    j += 1
  if N == dp[k]:
    print(k)
    break

Submission status: Runtime Error

Solution code:
def prime_factorization(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_factorization(N)
Length = len(a)
if Length%2 == 0:
    for i in range(Length-Length/2):
        x = a[Length/2]*a[Length/2+i]
else:
    for i in range(Length-int(Length/2)):
        x = a[int(Length/2)-1]*a[int(Length/2)+i-1]
y = N//x
print(x+y-2)

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    for n in range(int(N ** (1 / 2)))[::-1]:
        if N % n == 0:
            print(n - 1 + N // n - 1)
            return
main()

Submission status: Runtime Error

Solution code:
n = int(input())
stop = int(sqrt(n)) + 1
min_count = 10 ** 100
for a in range(1, stop):
    if n % a != 0:
        continue
    else:
        b = n // a
    count = a + b - 2
    if count < min_count:
        min_count = count
print(min_count)

Submission status: Runtime Error

Solution code:
N = int(input())
ans = []
for i in range(N):
	if i**2 > N:
		left = (i-1)
		break

for i in reversed(range(N)):
	if i**2 <N:
		right = (i-1)
		break
print(left,right)
left,right=right,left

for i in range(left**2,right**2+1):
	if N%i==0:
		ans.append(i+N//i-2)

print(min(ans))

Submission status: Runtime Error

Solution code:
N = int(input())

for i in range(math.floor(N**0.5),0,-1):
    if N % i == 0:
        x,y = i, N//i
        break
print(x+y-2)

Submission status: Runtime Error

Solution code:
def main():
  n = int(input())
  i = int(sqrt(n)) + 1
  while i * i > n: i -= 1
  while i >= 1:
    if n % i == 0
      print(i+n//i)
      return
    i -= 1
main()

Submission status: Runtime Error

Solution code:
import math

N=int(input())

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

Submission status: Runtime Error

Solution code:
import sys
import math

def propare():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))

    solve(N)

def solve(N: int):
    # Symmetry, a<=b, a<=math.sqrt(N)
    N_max = min(N, 1000000000000)
    a_max = int(math.sqrt(N_max))
    tmp_list = []
    for a in range(1, a_max):
        if N%a == 0:
            b = int(N/a)
            tmp_list.append((a, b))

    if tmp_list:
        answer = tmp_list[0][0] + tmp_list[0][1]

    for i_tp in tmp_list:
        tmp = i_tp[0] + i_tp[1]

        if tmp < answer:
            answer = tmp

    print(answer - 2)
    return

 
if __name__ == "__main__":
    propare()

Submission status: Runtime Error

Solution code:
import sys

def propare():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))

    solve(N)

def solve(N: int):
    N_max = min(N, 1000000000000)
    tmp_list = []
    for i in range(1, N_max):
        for j in range(1, N_max):
            if i*j == N:
                tmp_list.append((i, j))

    if tmp_list:
        answer = tmp_list[0][0] + tmp_list[0][1]

    for i_tp in tmp_list:
        tmp = i_tp[0] + i_tp[1]

        if tmp < answer:
            answer = tmp

    print(answer - 2)
    return

 
if __name__ == "__main__":
    propare()

Submission status: Runtime Error

Solution code:

N = int(input())

result1 = 0
result2 = 0

for count in range(2,N // 2):
    if N % count == 0:
        result1 = count


print(result1+ N // result1 -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)

    return divisors

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

    count = n + 1

    ls = make_divisors(n)

    for i in range(len(ls)):
        if i % 2 != 0:
            continue
        if ls[i] + ls[i+1] < count:
            count = ls[i] + ls[i+1]

    print(count-2)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())

divisors =[]
for i in range(1,int(n/2)+1):
    if n%i == 0:
        divisors.append(i)
divisors.append(n)
print(divisors)
x=len(divisors)
print(x)
gojyu=[]
for j in range(x-1):
    for k in range(x-1):
        if divisors[j]*divisors[k] == n:
            gojyu.append(divisors[j]+divisors[k]-2)
print(min(gojyu))

Submission status: Runtime Error

Solution code:
n = int(input())

divisors =[]
for i in range(1,n+1):
    if n%i == 0:
        divisors.append(i)
x=len(divisors)

gojyu=[]
for j in range(x-1):
    for k in range(x-1):
        if divisors[j]*divisors[k] == n:
            gojyu.append(divisors[j]+divisors[k]-2)
print(min(gojyu))

Submission status: Runtime Error

Solution code:
import math

N = int(input())

min_cand = 10**9

for i in range(1,(int(math.sqrt(N))+1):
  if N % i == 0 and min_cand < (i + (N // i)):
    min_cond = (i + (N // i))
    
print(min_cond - 2)

Submission status: Runtime Error

Solution code:
import math

a = int(input())

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = n** 0.5
if n%a == 0:
    print(int(2*a)-2)
else:
    while n%a != 0:
        a = a//1-1 
        if n%a == 0:
            print(int(a + n//a-2))
            exit()

Submission status: Runtime Error

Solution code:
import math

n = int(input())
num_i = 0

for i in range(1,int(math.sqrt(n))):
    if n%i == 0:
        num_i = i

num_j = n//num_i
ans = (num_i-1)+(num_j-1)

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100000)

N = int(input())

min = float('inf')

def dfs(x, y, count):
    global min

    if x<0 or y<0 or (((x+1)*(y+1))>N):
        return

    if (x+1)*(y+1)==N:
        
        if min > count:
            min = count
            return
        return

    dfs(x+1, y, count+1)
    dfs(x, y+1, count+1)

    return

dfs(0,0,0)

print(min)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100000)

N = int(input())

min = float('inf')

def dfs(x, y, count):
    global min

    if x<0 or y<0 or (((x+1)*(y+1))>N):
        return

    if (x+1)*(y+1)==N:
        
        if min > count:
            min = count
            return
        return

    dfs(x+1, y, count+1)
    dfs(x, y+1, count+1)

    return

dfs(0,0,0)

while 

print(min)

Submission status: Runtime Error

Solution code:
N = int(input())

min = float('inf')

def dfs(x, y, count):
    global min

    if x<0 or y<0 or (((x+1)*(y+1))>N):
        return

    if (x+1)*(y+1)==N:
        
        if min > count:
            min = count
            return
        return

    dfs(x+1, y, count+1)
    dfs(x, y+1, count+1)

    return

dfs(0,0,0)
print(min)

Submission status: Runtime Error

Solution code:
N = int(input())

min = float('inf')

def dfs(x, y, count):
    global min
    if (x+1)*(y+1)==N:
        
        if min > count:
            min = count
            return
        return
    if x<0 or y<0 or (((x+1)*(y+1))>N):
        return

    count = count + 1

    dfs(x+1, y, count)
    dfs(x, y+1, count)

    return

dfs(0,0,0)
print(min)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
r = list()
for a in range(1,int(math.sqrt(n))):
    if n % a == 0:
        b = n//a
        r.append(a+b-2)
print(min(r))

Submission status: Runtime Error

Solution code:
inp = int(input())
a = 1
b = 1
yn = prime_decomposition(inp)
for pon in range(-(-len(yn)//2)):
  a *= yn[pon]
  try:
    b *= yn[pon+1]
  except:
    pass
  pon += 1
print(a+b-2)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
N = int(input())
ans = float("inf")

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

Submission status: Runtime Error

Solution code:
import math
N = int(input())
ans = float("inf")

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

Submission status: Runtime Error

Solution code:
import math
a = int(input())
b = int(math.sqrt(a))-1
for i in range(b):
    x = a/b
    if x.is_integer():
        break
    else:
        b -= 1
print(int(x + b -2))

Submission status: Runtime Error

Solution code:
a = int(input())
b = int(math.sqrt(a))-1
for i in range(b):
    x = a/b
    if x.is_integer():
        break
    else:
        b -= 1
print(int(x + b -2))

Submission status: Runtime Error

Solution code:
n = int(input())

ans = 1000000000000

a = 1
while a * a <= n:
	if n % a != 0:
      continue
    b = n % a
    ans = min(ans, a + b - 2)
    a += 1

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

def min_walk(n):
    out = []
    for a in range(1, int(n**0.5)):
        if n % a == 0:
            out.append(a + (n//a) - 2)

    return min(out)


print(min_walk(n))

Submission status: Runtime Error

Solution code:
N = int(input())
ans = 10*10
#N<10**12より√N<10**6]
for i in range(1, i*i <=N):
    if (N % i != 0): continue
    j = N / i
    ans = min(ans, i + j - 2)

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
ans = 10*18
for i in range(1, i*i <=N):
    if (N % i != 0): continue
    j = N / i
    ans = min(ans, i + j - 2)

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
#掛け算表は対称行列
#対角成分に移動するときが最短移動
def make_divisors(n):
    divisors = []
    for i in range(1,int(n**0.5)+1):
        for n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort(reverse=True)
    return divisors
div = make_divisors(N)
a = div[0]
b = N // a
ans = (a - 1) + (b - 1)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

for i in reversed(range(int(N**0.5))):
    j = int(N/i)
    if i*j == N:
        print(i-1+j-1)
        break

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

n = int(input());
#n = [int(i) for i in input().split()];
#S = [str(s) for s in in_S]

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
    
m = make_divisors(n)
#print(m);

count = 0;
for i in range(0,len(m),2):
    #print(i);
    tmp =  (m[i]-1) + (m[i+1]-1);
    #print(tmp);
    if tmp < count or count == 0:
        count = tmp;
    #if n%i == 0 and n/i <= 9:
        #jud ='Yes';
print(count);

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())

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

print(int(ans))

Submission status: Runtime Error

Solution code:
import sympy
s=int(input())
sympy.divisors(s)
m=[]
for a in x:
    for b in x:
        if a*b==s and a<=b:
            k=a+b
            a=k-b
            m.append(k)
print(min(m)-2)

Submission status: Runtime Error

Solution code:
n = int(input())
factor = []

for i in range(1,int(n**1/2)):
    if n%i == 0:
        factor.append(i + n//i -2)
    else:
        continue

print(min(factor))

Submission status: Runtime Error

Solution code:
n = int(input())
int x = 1
res = n
while x * x <= n:
  if n % x == 0:
    res = min(res, x + n // x)
print(res)

Submission status: Runtime Error

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

a = []
m = math.floor(a**(1/2))
for i in range(1,m + 1):
    if n % i == 0:
        a.append(i + (n/i) - 2)

print(int(min(a)))

Submission status: Runtime Error

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

a = []
m = amth.floor(a**(1/2))
for i in range(1,m + 1):
    if n % i == 0:
        a.append(i + (n/i) - 2)

print(int(min(a)))

Submission status: Runtime Error

Solution code:
import math
A = int(input())
B = int(math.sqrt(A))
count = 0
for i in reversed(range(1,B)):
	if count == 0:
    	if A % i == 0:
			print(i+A/i-2)
        	count += 1

Submission status: Runtime Error

Solution code:
from math import ceil
N = int(input())
a = []
for i in range(ceil(N)):
    for j in range(ceil(N)):
        if N == i*j and j > i:
            a.append([i, j])


if len(a) > 1:
    b = a[0][0] + a[0][1]
else:
    b = a[0]
    print(sum(b)-2)
    exit()    


for k in range(1, len(a)):
    if b > a[k][0] + a[k][1]:
        b = a[k][0] + a[k][1]

print(b - 2)

Submission status: Runtime Error

Solution code:
num = int(input())
print(min(i + num // i - 2 for i in range(1, int(num ** (1 / 2))) if not num % i))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def prime_factor(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

N = int(input())

table = prime_factor(N)
table.sort()

if len(table)%2 == 0:
    tmp1 = 1
    tmp2 = 1
    for i in range(len(table)//2):
        tmp1 *= table[i]
        tmp2 *= table[i+len(table)//2]

    print(tmp1 + tmp2 - 2)

else:
    tmp1 = 1
    tmp2 = 1
    for i in range(len(table)//2):
        tmp1 *= table[i]
        tmp2 *= table[i+len(table)//2+i+1]

    tmp1 *= table[len(table)//2]
    print(tmp1 + tmp2 - 2)

Submission status: Runtime Error

Solution code:
N = int(input())
n = int((N**(1/2))//1)
s =[0]*n
for i in range(1,n+1):
  if N//i == 0:
    s[i] = i
maxs = s[0]
for j in range(1,n+1):
  if s[j] > maxs:
    maxs = s[j]
p = int(N/maxs)
walk = p + maxs - 2
print(walk)

Submission status: Runtime Error

Solution code:
スコード 

Copy
Copy
# a<=bとみなせるので探索回数は√nでよい
import math
n = int(input())
r_n = int(math.sqrt(n))+1
m = 10 ** 12
for i in range(1,r_n):
  if n % i == 0 and m > i + n / i - 2:
    m = i + n / i - 2
 
print(int(m))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
s = 0
N = int(input())
for i in range(1, int(N**(1/2))):
    if N%i == 0 and i > s:
        s = i
print(s+(N//s)-2)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

    gaps = [1,2,2,4,2,4,2,4,6,2,6]
    length, cycle = 11, 3
    f, fs, nxt = 2, [], 0
    while f * f <= n:
        while n % f == 0:
            fs.append(f)
            n /= f
        f += gaps[nxt]
        nxt += 1
        if nxt == length:
            nxt = cycle
    if n > 1: fs.append(n)
    return fs

import itertools
from itertools import combinations, chain
import copy 

# def powerset(L):
#   pset = set()
#   for n in range(len(L) + 1):
#     for sset in itertools.combinations(L, n):
#       pset.add(sset)
#   return pset
def powerset(iterable):
    "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
    
def list_diff(first, second):
        first = copy.copy(first)
        for s in second:
            first.remove(s)
        return first

def prod(lst):
    ret = 1
    for a in lst:
        ret *= a
    return ret

def sup(x):
    return [sorted(x[:i]+x[i+s:]) for i in range(len(x)) for s in range(len(x))]

def main():
    N = int(input())
    facs = factors(N)
    # st = powerset(facs)
    st=sup(facs)

    mn_ij = 10**12
    for i in st:
        i = list(i)
        j = list_diff(facs, i)
        i, j = prod(i), prod(j)

        mn_ij = min(mn_ij, i+j)

    # print(list(map(len,[ st, facs]) ))
    print(int(mn_ij-2))

if __name__ == "__main__":
    main()