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

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np

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 list_diff(first, second):
        first = first.copy()
        for s in second:
            first.remove(s)
        return first

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

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

        mn_ij = min(mn_ij, i+j)

    print(int(mn_ij-2))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np

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 list_diff(first, second):
        first = first.copy()
        for s in second:
            first.remove(s)
        return first

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

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

        assert i * j == N, f'{i} {j} {N}'
        mn_ij = min(mn_ij, i+j)

    print(int(mn_ij-2))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

Abs = int(np.sqrt(N))
if Abs ** 2 == N:
    print((Abs - 1) * 2)
    sys.exit(1)
else:
    min = N + 1
    min_i = 0
    for i in range(1, Abs + 1):
        tmp = N // i
        if tmp * i == N:
            if min > tmp:
                min = tmp
                min_i = i

print(min + min_i - 2)

Submission status: Runtime Error

Solution code:
N = int(input())

Abs = int(np.sqrt(N))
if Abs ** 2 == N:
    print((Abs - 1) * 2)
else:
    min = N + 1
    min_i = 0
    for i in range(1, Abs + 1):
        tmp = N // i
        if tmp * i == N:
            if min > tmp:
                min = tmp
                min_i = i

print(min + min_i - 2)

Submission status: Runtime Error

Solution code:
n=int(input())
2.i=int(n**0.5)
3.while i<n:
4.  if n%i==0:
5.    break
6.  else:
7.    i+=1
8.if i==n:
9.  print(i-1)
10.else:
11.  print(int(i+n/i)-2)

Submission status: Runtime Error

Solution code:
 N = int(input())
x = N
y = N
ansx = N
ansy = N
n = int(N**0.5)
for i in range(x+1):
    if i+1 > n:
        break
    for j in range(y+1):
        if j+1 > x+1:
            break
        if i*j == N:
            if ansx + ansy >i+j:
                ansx,ansy = i,j

print(ansx + ansy -2)

Submission status: Runtime Error

Solution code:
import math.sqrt as sqrt
n=int(input())
ans=1+n
if(n%2==0):
  ans=2+int(n/2)
  
for i in range(3,int(sqrt(n))+1,2):
  if(n%i==0):
    ans=min(ans,(i+int(n/i)))
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from math in sqrt
n = int(input())

m = int(sqrt(n))

print(m*2-1)

Submission status: Runtime Error

Solution code:
import math

N = int(input())

n = int(math.sqrt(N))
lens = []
for a in range(1, n):
  if N % a == 0:
    lens.append(a+N//a-2)

print(min(lens))

Submission status: Runtime Error

Solution code:
import numpy
n=input()
n=int(n)
list=[]

for i in range(1,n+1):
    for j in range(i,n+1):
        if(i*j>n):
            break
        elif(n==i*j):
            save=i-1+j-1
            list.append(save)
            
ans=min(list)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
if int(int(np.sqrt(n)) **2) == n:
    print(int(np.sqrt(n))*2 - 2)
else:
    a = 0
    for i in range(int(np.sqrt(n)))[::-1]:
        j = i + 1
        if n % j == 0:
            a = j
            break
    print(int(a-1 + n/a-1))

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <cmath>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
using namespace std;
#define INF 1000000007
#define ll long long
#define rep(i_, __start, __end) for(ll i_=(ll)__start; i_<(ll)__end; i_++)
#define print(_a) cout << _a << endl;
#define printarray(a, len) rep(ii,0,len) cout << a[ii] << " ";
#define printarray2(aa, len) rep(ij,0,len) printarray(aa[ij], aa[ij].size()); print("");



vector<ll> si;
void soinsuu(ll n){
  ll num=2;

  while(num*num <= n){
    if(n % num == 0){
      n /= num;
      si.push_back(num);
    }else{
      num++;
    }
  }

  if(n != 1){
      si.push_back(n);
  }

}

int main(){
    ll n, x=1, y=1;
    cin >> n;
    soinsuu(n);
    for (ll i=0; i<si.size()/2; i+=2){
      x *= si[i];
      y *= si[i+1];
    }
    if(si.size() % 2 == 1){
      x *= si[si.size() - 1];
    }
    print((x-1) + (y-1));
  
  return 0;
}

Submission status: Runtime Error

Solution code:
inport sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())

U = 10**6 + 100

div = np.arange(1, U, dtype=np.int64)
div = div[N%div==0]

div = np.union1d(div, N//div)

answer = (div + (N//div)).min() - 2
print(answer)

Submission status: Runtime Error

Solution code:
n = int(input())

div = 1

while n/div < div:
    if n % div == 0:
        ans = (div-1) + (n/div-1)
    div += 1

pritn(ans)

Submission status: Runtime Error

Solution code:
#ABC144_C
#素因数分解して、N＝なるべく差の小さい2つの因数の積、と考える
import math

init_N=int(input())
N=init_N
ans_list=[]
A=1
B=1

for i in range(2,int(math.sqrt(init_N))+1):
    while 1:  
        cnt+=1
        if N%i==0:
            ans_list.append(i)
            N=N//i
        else:
            break
if N==1:
    pass
else:
    ans_list.append(N)

if len(ans_list)==1:
    print(str(init_N-1))
else:
    while len(ans_list)>0:
        A=A*ans_list.pop(0)
        print(A)
        if len(ans_list)!=0:
            B=B*ans_list.pop(0)
            print(B)
    print(str(A+B-2))

Submission status: Runtime Error

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

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)

times = 10**12

for j in range(0, len(divisors), 2):
	time = (divisors[j] - 1) + (divisors[j+1] - 1)
	if time < times:
		times = time
print(times)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

N = int(input())
ans = solve(N)
print(ans)

Submission status: Runtime Error

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

for x in range(n):
  for y in range(n):
    if x * y == n:
      li.append(x+y-2)

result = min(li) 
print(result)

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 main():
    Min = 2000000000000
    divisors = make_divisors(int(input()))
    if len(divisors)%2==1:
        divisors[len(divisors)] = divisors[len(divisors)-1]
    #print(divisors)
    for i in range(0,len(divisors)-1,2):
        Min = min(divisors[i]+divisors[i+1],Min)
    print(Min-2)

main()

Submission status: Runtime Error

Solution code:
n = int(input())
r = int(n**0.5)
revList = [i for i in range(r)]
revList = revList[1:]
revList.reverse()

for i in revList:
  if n % i == 0:
    res = int(n/i) + i - 2
    break
print(res)

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':

	n = int(input())
	m = int(n//2)

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

	print(end)

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)
	return divisors

total=sorted(make_divisors(N))
print(total[1]-1+total[len(total)-2]-1)

Submission status: Runtime Error

Solution code:
n = int(input())

for i in range(1, int(n**(1/2)) , 1):
    if n%i == 0:
        j = n//i
i = n//j

ans = i-1 + j-1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

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

ans = i-1 + j-1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
a = 1
while a * a <= N:
  if N % a = 0:
    k = a
  a += 1
b = N //k
print(b + k - 2)

Submission status: Runtime Error

Solution code:
N = int(input())
a = 1
while a * a <= N:
  if N % a = 0:
    k = a
  a += 1
print(k + (N // k) - 2)

Submission status: Runtime Error

Solution code:
N = int(input())
a = 1
while a * a <= N:
  if N % a = 0:
    k = a
  a += 1
print(k + (N/k) - 2)

Submission status: Runtime Error

Solution code:
N = int(input())
a = 1
while a * a <= N:
  if N % a = 0:
    k = a
  a += 1
print(k + (N//k) -2)

Submission status: Runtime Error

Solution code:
N = int(input())
a = 2
while a * a <= N:
  if N % a = 0:
    k = a
  a += 1
print(k + N//k -2)

Submission status: Runtime Error

Solution code:
n=int(input())
s=[]
d=[(0,0)]

for i in range(1,n+1):
  if n%i==0:
    s.append((i-1,n//i-1))

for i in s:
  d.append(i[0]+i[1])

print(min(d))

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())
divs = make_divisors(N)
if len(divs) % 2 == 0:
    print(divs[len(divs)//2 - 1] + divs[len(divs)//2] - 2)
else:
    print(divs[len(divs//2)] * 2 - 2)

Submission status: Runtime Error

Solution code:
n = int(input())
root_n = 0
while True:
    if root_n * root_n < n:
        root_n += 1
    else:
        break

devidor = 1
for i in range(1, root_n+1):
    if n % i == 0:
        devidor = i
devidor2 = n // devidor

print(devidor + devidor2 - 2)n = int(input())
root_n = 0
while True:
    if root_n * root_n < n:
        root_n += 1
    else:
        break

devidor = 1
for i in range(1, root_n+1):
    if n % i == 0:
        devidor = i
devidor2 = n // devidor

print(devidor + devidor2 - 2)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
ans = 10^12
for a in range(int(np.sqrt(N))):
  if N % a != 0:
    continue
  step = a + N/a -2
  if step < ans:
    ans = step
    
print(str(ans))

Submission status: Runtime Error

Solution code:

class Solution:
    def solve(self, n: int) -> int:

        maxDivisor = int(math.sqrt(n) + 0.5)

        for i in range(1, maxDivisor + 1):
            if n % i == 0:
                p = i

        q = n // p

        return p+q-2


if __name__ == '__main__':

    # standard input
    n = int(input())

    # solve
    solution = Solution()
    print(solution.solve(n))

Submission status: Runtime Error

Solution code:
from math import sqrt
n = int(input())
d = 1000000000000000000000
for i in range(1, sqrt(n)+1):
  if n % i == 0:
    d = min(d, i + n // i - 2)
print(d)

Submission status: Runtime Error

Solution code:
n = int(input())
d = 1000000000000000000000
for i in range(1, int(sqrt(n))+1):
  if n % i == 0:
    d = min(d, i + n // i - 2)
print(d)

Submission status: Runtime Error

Solution code:
n = int(input())
d = 1000000000000000000000
for i in range(1, sqrt(n)+1):
  if n % i == 0:
    d = min(d, i + n // i - 2)
print(d)

Submission status: Runtime Error

Solution code:
import math
ans = 10**12
n = int(input())
for a in range(1,int(math.sqrt(n)):
  for b in range(1,int(math.sqrt(n)):
    if a * b == n:
      ans_n = a + b -2
      if ans > ans_n:
        ans = ans_n
print(ans)

Submission status: Runtime Error

Solution code:
import math
ans = 10**12
n = int(input())
for a in range(1,int(math.sqrt(N)):
  for b in range(1,int(math.sqrt(N)):
    if a * b == n:
      ans_n = a + b -2
      if ans > ans_n:
        ans = ans_n
print(ans)

Submission status: Runtime Error

Solution code:
ans = 10**12
n = int(input())
for a in range(1,int(math.sqrt(N)):
  for b in range(1,int(math.sqrt(N)):
    if a * b == n:
      ans_n = a + b -2
      if ans > ans_n:
        ans = ans_n
print(ans)

Submission status: Runtime Error

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

array = []
for i in range(1,math.floor((N)**0.5)+1)
    if N // i == 0:
        num = N // i
        array.append(num)
l = len(array)
print(int(array[l]) + (N / int(array[l])))

Submission status: Runtime Error

Solution code:
N = int(input())
array = []
for i in range(1,N+1):
    if N // i == 0 and i <= (N // i):
        num = N // i
        array.append(num)
l = len(array)
print(int(array[l]) + (N / int(array[l])))

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:
        tmp=n//i
        ans.append(abs(i-1)+abs(tmp-1))
print(min(ans))

Submission status: Runtime Error

Solution code:
import math

n= int(input())
def is_prime(n):
    if n == 1: return False

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

    return True

res  = []
if is_prime(n):
    res = n - 1
else:
    for t in range(1, int(math.sqrt(n)) + 1):
        if n % t == 0:
                res.append(n//t + t - 2)


print(min(res))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

N = int(input())

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

Submission status: Runtime Error

Solution code:
input_num = int(input())
num_sqrt = int(math.sqrt(input_num))

minimam = input_num
for i in range(num_sqrt+1,0,-1):
    q, mod = divmod(input_num, i)
    if mod == 0:
        distance = q + i -2
        if minimam > distance:
            minimam = distance
print(minimam)

Submission status: Runtime Error

Solution code:
import math
def main1():
    input_num = int(input())
    num_sqrt = int(math.sqrt(input_num))

    minimam = input_num
    for i in range(num_sqrt+1,0,-1):
        q, mod = divmod(input_num, i)
        if mod == 0:
            distance = q + i -2
            if minimam > distance:
            minimam = distance
    print(minimam)

Submission status: Runtime Error

Solution code:
import math

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

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())

l = np.empty(n)
l[:] = np.nan

k = 0
i = 1

while i <= n:
  if n % i == 0:
    l[k] = i + (n // i) - 2
    k += 1
  i += 1
print(int(np.nanmin(l)))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())

l = np.zeros(n)
l[:] = np.nan

k = 0
i = 1

while i <= n:
  if n % i == 0:
    l[k] = i + (n / i) - 2
    k += 1
  i += 1
print(int(np.nanmin(l)))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())

l = np.zeros(n)
l[:] = np.nan

k = 0
i = 1

while i <= n ** 0.5:
  if n % i == 0:
    l[k] = i + (n / i) - 2
    k += 1
  i += 1
print(int(np.nanmin(l)))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())

l = np.empty(n)
l[:] = np.nan

k = 0
i = 1

while i <= n ** 0.5:
  if n % i == 0:
    l[k] = i + (n / i) - 2
   　k += 1
  i += 1
print(int(np.nanmin(l)))

Submission status: Runtime Error

Solution code:
import numpy as np
import math
n = int(input())
l = np.empty(n)
l = np.nan

k = 0
i = 1
while i <= n ** 0.5:
  if n % i == 0:
    l[k] = i + (n / i) - 2
   　k += 1
  i += 1
print(int(np.nanmin(l)))

Submission status: Runtime Error

Solution code:
import numpy as np
import math
n = int(input())
l = np.empty(n)
l = np.nan

k = 0
i = 1
while i <= n ** 0.5:
  if n % i == 0:
    l[k] = i + (n / i) - 2
  i += 1
print(int(np.nanmin(l)))

Submission status: Runtime Error

Solution code:
import numpy as np
import math
n = int(input())
l = np.empty(n)
l = np.nan

k = 0
while i <= n ** 0.5:
  if n % i == 0:
    l[k] = i + n / i - 2
  i += 1
print(int(np.nanmin(l)))

Submission status: Runtime Error

Solution code:
import numpy as np
import math
n = int(input())
l = np.empty(floor(n ** 0.5))
l = np.nan

k = 0
for i in range(1,floor(n ** 0.5)):
  if n % i == 0:
    l[k] = i + n // i - 2
    k += 1
print(int(np.nanmin(l)))

Submission status: Runtime Error

Solution code:
import numpy as np
import math
n = int(input())
l = np.empty(floor(n ** 0.5))
l = np.nan

k = 0
for i in range(floor(n ** 0.5)):
  if n % i == 0:
    l[k] = i + n // i - 2
    k += 1
print(int(np.nanmin(l)))

Submission status: Runtime Error

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

l = np.empty(n)
l[:] = np.nan
k = 0

for i in range(1,n):
  if n % i == 0:
    l[k] = i + (n / i)
    k += 1
print(int(np.nanmin(l) - 2))

Submission status: Runtime Error

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

l = np.empty(n)
l[:] = np.nan
k = 0
for i in range(1,n):
  if n % i == 0:
    l[k] = i + (n / i)
    k += 1
print(int(np.nanmin(l)))

Submission status: Runtime Error

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

l = np.empty(n)
l[:] = np.nan
k = 0
for i in range(1,n):
  if n % i == 0:
    l[k] = int(i + (n / i))
    k += 1
print(np.nanmin(l))

Submission status: Runtime Error

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

l = np.empty(n)
l[:] = np.nan
k = 0
for i in range(n):
  if n % i == 0:
    l[k] = int(i + (n / i))
    k += 1
print(np.min(l))

Submission status: Runtime Error

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

l = np.empty(n)
l[:] = np.nan

for i in range(n):
  if n % i == 0:
    l[i] = int(i + (n / i))
print(np.min(l))

Submission status: Runtime Error

Solution code:
import math
n = int(input())
half = math.floor(n**0.5)
#print(half)

for i in range(half+1,0,-1):
  if n % i == 0 and 1 <=n/i<=9 :
    num1,num2 = i,n//i  
    #print("Yes")
    break

if not num1:
  print(n-1)
else:
  print(num1+num2-2)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
half = math.floor(n**0.5)
#print(half)

for i in range(half+1,0,-1):
  if n % i == 0 and 1 <=n/i<=9 :
    num1,num2 = i,n//i  
    #print("Yes")
    break

print(num1+num2-2)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(N - 1):
    if S[i] == S[i + 1]:
        continue
    ans += 1
print(ans + 1)

Submission status: Runtime Error

Solution code:
import math

def dictcheck(dict):
    min = 0
    for k,v in dict.items():
#        print("k:",k ,"+", "v:",v)
        if min == 0:
            min=(int(k)-1)+(int(v)-1)
        elif min > (int(k)-1)+(int(v)-1):
            min = (int(k)-1)+(int(v)-1)
        else:
            continue
    print(min)

def main():
    N = int(input())
    i = 2
    tmpdict= {}
    while i < math.sqrt(N):
        if N % i == 0:
            tmpdata = {i:N/i}
            tmpdict.update(tmpdata)
            i+=1
        else:
            i+=1
    if len(tmpdict)==0:
        tmpdata = {1,N-1}
        tmpdict.update(tmpdata)
#    print(tmpdict)
    dictcheck(tmpdict)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sqrt from math
N=int(input())
for i in range(int(sqrt(N))+1,-1,-1):
    if N%i==0:
        print(i-1+N//i-1)
        exit()

Submission status: Runtime Error

Solution code:
import sqrt from math
N=int(input())
for i in range(int(sqrt)+1,-1,-1):
    if N%i==0:
        print(i-1+N//i-1)
        exit()

Submission status: Runtime Error

Solution code:
N = int(input())
i = 2
while True:
    for j in range(1,i):
        if i*j == N:
            ANS = 1+j-2
            print(ANS)
            breakloop = True
            break
    if breakloop:
        break

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
n = np.sqrt(N)
m = int(n)

count = N - 1
for i in range(n,2,-1):
    if (N % i)==0:
        ans = i +(N % i) -2
        count = ans
        break

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
b = input()
a = int(b)

c = int(math.sqrt(a))

for i in range(10000000):
    d = a / (c + i)
    if (d.is_integer() == True) & (i <= 10000):
        break
    if i > 10000:
        for j in range(1000000):
            f = a / (2 + j)
            if f.is_integer() == True:
                break
        break

if i > 1000:
    g = f + j
    print(int(g))
else:
    e = d + c + i - 2
    print(int(e))

Submission status: Runtime Error

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

using namespace std;

int main(){
  long long n;
  cin >> n;
  long long ans = n+1;
  for(long long i = 1; i <= sqrt(n); i++){
    if( n%i == 0 ){
      long long j = n/i;
      if( i+j < ans )
        ans = i+j;
    }
  }
  cout << ans << endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
N=int(input())
K=list()

for i in range(1,int(N**0.5)+1):
  if(N/i in list(range(1,N+1))):
    M=int(N/i)  #N<=M
    L=i
    K.append(M+L-2)
    
print(min(K))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
yu = int(input())
result = []
for i in range(1,round(math.sqrt(yu))):
	if yu % i == 0:
		result.append(i)

print(round(max(result)-1+(yu/max(result))-1))

Submission status: Runtime Error

Solution code:
N = int(input())
a = int(N**0.5)
ans = 10**6
for x in range(0,a+1):
    b = N / x
    if b == int(b):
        if a + b - 2 < ans:
            ans = a+b-2
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
m = int(sqrt(m))
for i in reversed(range(1, m)):
  if N%i==0:
    j = N//i
    print(i+j-2)

Submission status: Runtime Error

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

i = int(input())
a = factorization(i)
for i in range(len(a)-1):
  if a[i][0] == a[i + 1][0]:
    a.remove(a[i])
flag = False
for i in a:
  
  if i[1] == 1:
    
    flag = True
  else:
    flag = False

if flag:
  b = [0 if i % 2 == 0 else 1 for i in range(len(a))]
else:
  b = [i[1]//2 for i in a]

c = [a[i][1]-b[i] for i in range(len(b))]

d = [a[i][0]**b[i] for i in range(len(a))]


f = 1
for i in range(len(c)):
  f *= a[i][0]**c[i]

g = 1
for i in range(len(c)):
  g *= d[i]

print(f + g - 2)

Submission status: Runtime Error

Solution code:
n = int(input())

for i in range(1, n**.5+1):
  if n%i == 0:
    p = i

q = n//p

print(p+q-2)

Submission status: Runtime Error

Solution code:
from sympy import divisors as d

n = int(input())
p = max([i for i in d(n) if i <= n**.5])
q = n//p

print(p+q-2)

Submission status: Runtime Error

Solution code:
# C
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)
memo = 0
maX = divisors[0] + divisors[len(divisors) - 1]
for (i, r) in zip(make_divisors, reversed(make_divisors)):
    maX = min(i + r, maX)
    memo = i
    if memo == r:
        break
print(maX)

Submission status: Runtime Error

Solution code:
n = int(input())
data = []
N = n
count = 2
while count <= int(N**(1/2)+1):
  if n % count == 0:
    n = n / count
    data.append(count)
    continue
  else:
    count += 1
  if count == int(N**(1/2)) and n != 0:
    data.append(n)
    
#print(data)
sum_data = []
if len(data) == 1:
  print(int(data[0]))
  exit()
for i in range(1,len(data)-1):
  sum_data.append(sum(data[:i]) + sum(data[i:]))

#print(sum_data)

print(int(min(sum_data)))

Submission status: Runtime Error

Solution code:
n = int(input())
data = []
N = n
count = 2
while count <= int(N**(1/2)+1):
  if n % count == 0:
    n = n / count
    data.append(count)
    continue
  else:
    count += 1
  if count == int(N**(1/2)) and n != 0:
    data.append(n)
    
#print(data)
sum_data = []
if len(data) == 1:
  print(data[0])
  exit()
for i in range(1,len(data)-1):
  sum_data.append(sum(data[:i]) + sum(data[i:]))

#print(sum_data)

print(min(sum_data))

Submission status: Runtime Error

Solution code:
import math
from sympy import primerange
import sys
sys.setrecursionlimit(10**6) 
inn = n = int(input())
num = int(math.sqrt(n)) + 1
primlist = list(primerange(2,num)) 

for i in primlist:
    if inn % i == 0:
        while inn % num != 0:
            num -= 1
        else:
            print(num+ inn//num -2)
            break
        
else:
    print(inn-1)

Submission status: Runtime Error

Solution code:
import math
from sympy import primerange
inn = n = int(input())
num = int(math.sqrt(n)) + 1
primlist = list(primerange(2,num)) 
for i in primlist:
    if inn % i == 0:
        while inn % num != 0:
            num -= 1
        else:
            print(num+ inn//num -2)
            break        
else:
    print(inn-1)

Submission status: Runtime Error

Solution code:
import math
from sympy import primerange
inn = n = int(input())
num = int(math.sqrt(n)) + 1
primlist = list(primerange(2,num)) 

for i in primlist:
    if inn % i == 0:
        while inn % num != 0:
            num -= 1
        else:
            print(num+ inn//num -2)
            break
        
else:
    print(inn-1)

Submission status: Runtime Error

Solution code:
from math import sqrt

n = int(input())
for i in range(sqrt(n), 1, -1):
  if n % i == 0:
    print(i + n/i -2)
    break
else:
  print(n-1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = input()
N_sqrt = int(np.sqrt(N))+1
N_ = [i for i in range(2, N_sqrt) if N % i == 0]

if len(N_) == 0:
    print(N-1)
else:
    pair = [(i, int(N/i)) for i in N_]
    my_lambda = lambda x : sum(x)
    x = list(map(my_lambda, pair))
    print(min(x)-2)

Submission status: Runtime Error

Solution code:
import numpy as np
import math

def pk(n):
  b = 2
  fct = []
  while b * b <= n:
    while n % b == 0:
      n //= b
      fact.append(b)
    b += 1
  if n > 1:
    fct.append(n)
  return fct

n = int(input())
temp = np.prod(pk(n))
sqi = int(math.sqrt(temp))
while 1:
  if temp % sqi 1= 0:
    sqi += 1
  else:
    break
i = sqi
j = temp // sqi
print(i + j -2)

Submission status: Runtime Error

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

Submission status: Runtime Error

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