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: Wrong Answer

Solution code:
# 素因数分解
# 戻り値: リスト
def prime_factor(n):
    ass = []
    for i in range(2,int(n**0.5)+1):
        while n % i==0:
            ass.append(i)
            n = n//i
    if n != 1:
        ass.append(n)
    return ass

N = int(input())
ass = prime_factor(N)
if len(ass) == 1:
    print(ass[0] - 1)
    exit()

ans = 10**10
for i in range(1, len(ass)):
    total1 = 1
    total2 = 1
    for j in ass[:-i]:
        total1 *= j
    for j in ass[-i:]:
        total2 *= j
    total = total1 + total2 - 2
    ans = min(ans, total)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())


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

print(make_divisors(n)-2)

Submission status: Wrong Answer

Solution code:
# 素因数分解
# 戻り値: リスト
def prime_factor(n):
    ass = []
    for i in range(2,int(n**0.5)+1):
        while n % i==0:
            ass.append(i)
            n = n//i
    if n != 1:
        ass.append(n)
    return ass

N = int(input())
ass = prime_factor(N)
if len(ass) == 1:
    ans = ass[0] - 1
else:
    ans = 1
    for i in ass[:-1]:
        ans *= i
    ans += ass[-1] - 2
print(ans)

Submission status: Wrong Answer

Solution code:
from functools import lru_cache


def factorize(n):
    f = []
    tmp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        while tmp % i == 0:
            f.append(i)
            tmp //= i
    if tmp != 1:
        f.append(tmp)
    if not f:
        f.append(n)
    return f


def distance(s):
    a, b = 1, 1
    for i, si in enumerate(s):
        if si == "0":
            a *= factors[i]
        else:
            b *= factors[i]
    return a + b - 2


@lru_cache()
def kp(i, s):
    if i == 0:
        return 0, s
    else:
        if distance("0" + s) < distance("1" + s):
            return kp(i - 1, "0" + s)
        else:
            return kp(i - 1, "1" + s)


N = int(input())
factors = factorize(N)
dist, bit = kp(len(factors), "")
print(distance(bit))

Submission status: Wrong Answer

Solution code:
from functools import lru_cache


def factorize(n):
    f = []
    tmp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        while tmp % i == 0:
            f.append(i)
            tmp //= i
    if tmp != 1:
        f.append(tmp)
    if not f:
        f.append(n)
    return f


def distance(s):
    a, b = 1, 1
    for i, si in enumerate(s):
        if si == "0":
            a *= factors[i]
        else:
            b *= factors[i]
    return a + b - 2


def kp(i, s):
    if i == 0:
        return 0, s
    else:
        if distance("0" + s) < distance("1" + s):
            return kp(i - 1, "0" + s)
        else:
            return kp(i - 1, "1" + s)


N = int(input())
factors = factorize(N)
dist, bit = kp(len(factors), "")
print(distance(bit))

Submission status: Wrong Answer

Solution code:
from functools import lru_cache


def factorize(n):
    f = []
    tmp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        while tmp % i == 0:
            f.append(i)
            tmp //= i
    if tmp != 1:
        f.append(tmp)
    if not f:
        f.append(n)
    return f


def distance(s):
    a, b = [], []
    for i, si in enumerate(s):
        if si == "0":
            a.append(factors[i])
        else:
            b.append(factors[i])
    return abs(sum(a) - sum(b))


def kp(i, s):
    if i == 0:
        return 0, s
    else:
        if distance("0" + s) < distance("1" + s):
            return kp(i - 1, "0" + s)
        else:
            return kp(i - 1, "1" + s)


def answer(s):
    x, y = 1, 1
    for i, si in enumerate(s):
        if si == "0":
            x *= factors[i]
        else:
            y *= factors[i]
    return x + y - 2


N = int(input())
factors = factorize(N)
dist, bit = kp(len(factors), "")
print(answer(bit))

Submission status: Wrong Answer

Solution code:
N = int(input())

YESFLAG = False

for i in range(1, 10):
    for j in range(1, 10):
        if i * j == N :
            YESFLAG = True
            break
    if YESFLAG :
        break

print(i - 1 + j - 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 10**12
for i in range(1, math.ceil(math.sqrt(n))):
    if n%i != 0:
        continue
    ans = min(ans, i+int(n/i)-2)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
factor = []
tmp = n
for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
    while tmp % i == 0:
        factor.append(i)
        tmp //= i
if tmp != 1:
    factor.append(tmp)
if len(factor) == 0:
    factor.append(n)

Submission status: Wrong Answer

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


#print(make_divisors(50))

i= 0

A = int(input())
A_d = make_divisors(A)

while A_d[i]< A**0.5:
    count = i
    i += 1

result = []
result.append(A_d[count])
result.append(int(A / A_d[count]))

#print(result)

result_sum = result[0] + result[1] - 2

print(result_sum)

Submission status: Wrong Answer

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

X = int(input())
n = f(X)
q = len(n)

if len(n) == 1: print(X-1)
else: 
    a = 1
    b = 1   
    for i in range(q):
        if a < b: a = a*n[q-i-1]
        else: b=b*n[q-i-1]
    print(a+b-2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

X = int(input())
n = f(X)
if len(n) == 1: print(X-1)
else: 
    a = 1
    b = 1
    for i in range(len(n)):
        if i%2 == 0: a = a*n[i]
        else: b=b*n[i]
    print(a+b-2)

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = n+1
for x in range(int(n**0.5), 2, -1):
    if(n % x == 0):
        ans = x + n//x
        break
print(ans-2)

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = n+1
for x in range(int(n**0.5)+1, 2, -1):
    if(n % x == 0):
        ans = x + n//x
        break
print(ans-2)

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = n+1
for x in range(int(n**0.5)+1, 2, -1):
    if(n % x == 0):
        ans = x + int(n/x)
        break
print(ans-2)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

Submission status: Wrong Answer

Solution code:
n= int(input())
m=n
for i in range(n):
    for j in range(n):
        if i*j==n:
            if m>i+j-2:
                m=i+j-2
print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())

# print(N)

ans = N
i = 1
while i * i < N:
    # print(i)
    
    div, mod = divmod(N, i)
    
    if mod == 0:
        # print(i)
        # print(div)
        # print(mod)
        
        ans = min(ans, ((i - 1) + (div - 1)))
    
    i += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

Submission status: Wrong Answer

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

div = make_divisors(int(input()))
i, j = div[-1]
print(i+j-2)

Submission status: Wrong Answer

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

ans = 10**12

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

print(ans)

Submission status: Wrong Answer

Solution code:
from enum import Enum
from queue import Queue

import numpy as np

import collections
import bisect
import sys
import math

from scipy.sparse.csgraph import floyd_warshall

BIG_NUM = 200000000000
MOD = 1000000007
EPS = 0.000000001

N = int(input())
ans = BIG_NUM

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

print(ans)

Submission status: Wrong Answer

Solution code:
def work_through(): 
  i, j = 1, 1
  cnt = 0

  arr = []
  arr.append([i, j])

  n = int(input())

  while True:
    length = len(arr)
    for i in range(0, length):
      x, y = arr.pop()
      if x * y == n:
        return cnt
      arr.append([x + 1, y])
      arr.append([x, y + 1])
    cnt += 1

print(work_through())

Submission status: Wrong Answer

Solution code:
import math
 
n = int(input())
n_h = round(math.sqrt(n))

yakusu = [1]
for i in range(1, n_h):
    if n % i == 0:
        yakusu.append(i)

if yakusu[-1]*yakusu[-1] == n:
    ans = yakusu[-1]*2 -2
else:
    tmp = n / yakusu[-1]
    ans = tmp + yakusu[-1] - 2

print(int(ans))

Submission status: Wrong Answer

Solution code:
import math
import copy

n=int(input())

i=int(n**0.5)
j=0
# print(i)

for i in range(i+1,0,-1):
    # print(i)
    if n==i:
        print(n-1)
        break
    if n%i==0:
        j=n/i
        print(i+j-2)
        break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
m = int(input())
a = {}
for i in range(1, int(m**0.5)+1):
    if m % i == 0:
        n = m // i
        a[i] = n
ans =[]
for i,j in a.items():
    b = i + j
    ans.append(b)
    
print(ans[-1]-2)

Submission status: Wrong Answer

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

#input
N = int(input())

#output
import math
M = int(math.sqrt(N))

ans = N
for i in reversed(range(1, M)):
    if float.is_integer(N/i):
        a = i
        b = int(N/i)
        c = a + b -2
        ans = min(ans, c)
        
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
i=1
ans=10**13
while(i*i<=n):
    if(n%i==0):
        ans=min(ans,n/i+i-2)
    i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
# 1行目の入力を数値として扱う
n = int(input())

# 答えの最大値
ans = 10 ** 12

# ループ(1からnの平方根まで)
for i in range(1, int(n ** 0.5)):
    m = n % i
    if m == 0:
        d = int(n / i)
#        print("i:" + str(i) + ", d:" + str(d))
        t = (i - 1) + (d - 1)
        if t < ans:
            ans = t

# 答えの出力
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = N
for i in range(1, N):
    for j in range(1, N):
        if N == i * j:
            flag = i + j -2
            if flag <= s:
                s = flag

print(s)

Submission status: Wrong Answer

Solution code:
"""
制約
2≦N≦10^12
Nは整数
"""
#入力
N = int(input())

list=[]

for i in range(1,int(N**0.5+1)):
  if N%i==0:
    list.append(i+N/i)

print(min(list)-2)

Submission status: Wrong Answer

Solution code:
import numpy as np

def isPrime(n):
  s = int(np.sqrt(n))
  for i in range(2, s+1):
    if n % i == 0:
      return False
  return True

def sum_devisor(n):
  s = int(np.sqrt(n))
  while(n % s != 0):
    s -= 1
  return s + n/s

n = int(input())
if isPrime(n) == True:
  print(n-1)
else:
  print(sum_devisor(n)-2)

Submission status: Wrong Answer

Solution code:
n = int(input())


def devide2(x):
    ar = []
    for i in range(1, int(x**0.5)):
        if x % i == 0:
            ar.append([i, x // i])
    return ar


kumi = devide2(n)

ans = 10 ** 12 + 1000
for i in range(len(kumi)):
    ans = min(ans, sum(kumi[i]))

print(ans - 2)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
Min = float('inf')
Max = math.ceil(math.sqrt(N))
for i in range(1,Max):
    if N%i==0:
        b = N//i
        Min = min(Min,i+b-2)
print(Min)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
MIN = n
for x in range(1,int(np.sqrt(n))):
    if n % x == 0:
        MIN = min([MIN,x + n/x - 2])
print(int(MIN))

Submission status: Wrong Answer

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

List = make_divisors(N)

print(List[-2]+List[-1]-2)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
MIN = n
for x in range(1,int(np.sqrt(n)+100)):
    if n % x == 0:
        MIN = min([MIN,x + n/x - 2])
    print(x)
print(int(MIN))

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
MIN = n
for x in range(1,int(np.sqrt(n))):
    if n % x == 0:
        MIN = min([MIN,x + n/x - 2])
    print(x)
print(int(MIN))

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
MIN = n
for x in range(1,int(np.sqrt(n))):
    if n % x == 0:
        MIN = min([MIN,x + n/x - 2])
    print(x)
    x += 1
print(int(MIN))

Submission status: Wrong Answer

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

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

print(int(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
num_a = 1
num_b = N
i = 2

while num_a <= num_b and i < N**0.5:
    if num_b % i == 0:
        num_a = int(num_a * i)
        num_b = int(num_b / i)    
    else:
        i += 1
print(int(num_a+num_b-2))

Submission status: Wrong Answer

Solution code:
N = int(input())
num_a = 1
num_b = N
i = 2

while num_a <= num_b and i < N**0.5:
    if num_b % i == 0:
        num_a = num_a * i
        num_b = num_b / i    
    else:
        i += 1
print(int(num_a+num_b-2))

Submission status: Wrong Answer

Solution code:
N = int(input())
num_a = 1
num_b = N
i = 2

while num_a <= num_b and i < N**0.5:
    if num_b % i == 0:
        num_a = num_a * i
        num_b = num_b / i    
    else:
        i += 1
print(num_a+num_b-2)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 10 ** 12 +1
for i in range(n):
  k = i+1
  if n%k == 0:
    ans = min(ans, n//k + k -2)
  if i ** 2 < n:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc144/tasks/abc144_c
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
import math
from heapq import heappush, heappop, heapify


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

    v = 1
    while v * v <= n:
        v += 1

    for i in range(v, 0, -1):
        if v % i == 0:
            print(i + v // i - 2)
            return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc144/tasks/abc144_c
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
import math
from heapq import heappush, heappop, heapify


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

    v = 1
    while v * v <= n:
        v += 1

    ans = 10**15
    for i in range(1, v):
        if v % i == 0:
            print(i + v // i - 2)
            return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc144/tasks/abc144_c
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
import math
from heapq import heappush, heappop, heapify


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

    v = 1
    while v * v <= n:
        v += 1

    ans = 10**15
    for i in range(1, v):
        for j in range(1, n):
            if i * j == n:
                ans = min(ans, i + j - 2)
            if i * j > n:
                break
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc144/tasks/abc144_c
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop, heapify


# 素因数分解
def prime_list(n):
    li = []

    i = 2
    while i * i <= n:
        while n % i == 0:
            n //= i
            li.append(i)
        i += 1

    if n > 1:
        li.append(n)
    return li


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

    if len(li) == 1:
        print(li[0] - 1)
        return

    heapify(li)
    while len(li) > 2:
        val1 = heappop(li)
        val2 = heappop(li)
        heappush(li, val1 * val2)

    print(li[1] - 1 + li[0] - 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

N = int(input())


def main():

    factorized = factorizer(N)

    if len(factorized) == 2:
        print(N - 1)
        quit()

    end = N ** 0.5
    minv = 10000000000
    for i in range(1, N):
        for j in range(i, N):
            # print("i:{0}  j:{1}  i*j:{2}  N:{3}".format(i, j, i * j, N))
            if (i * j) == N:
                minv = min(minv, i + j - 2)

    print(minv)


def factorizer(n):
    """
    素因数分解するということは、
    2 ~ Nまでの数で割り続けるということ　試し割り
    割れなくなったら次の数で割る。
    素数を除いて、素因数の最大値は√nなので、それを超えたらやめる
    """
    res = {1: 1}  # １は必ずある
    calcEnd = n ** 0.5

    for i in range(2, int(calcEnd) + 2, 1):
        while n % i == 0:
            if res.get(i) is None:
                res[i] = 1
            else:
                res[i] += 1
            n /= i
            # print("n:{0}".format(n))

    # GCDが素数だった時の処理
    if n > 1:
        res[int(n)] = 1

    # print("res is {}".format(res))
    return res


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
ans=float('inf')
i=2
while i*i<=N:
  if N%i==0:
    ans = min(ans,i+(N//i)-2)
  i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())

    ans = N - 1
    i = 1
    while i * i < N:
        if N % i == 0:
            j = N // i
            ans = min(ans, i+j-2)
        i += 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

res = N - 1
mid = int(math.sqrt(N))

for i in range(2, mid):
    if N % i == 0:
        res = min((i -1)+(N / i - 1), res)

print(int(res))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

Submission status: Wrong Answer

Solution code:
# 約数s
def make_divisors(n):
    divisors = []
    ret = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ret.append((i,n//i))
    return ret

if __name__ == "__main__":
    n = int(input())
    ret = make_divisors(n)
    print(ret)
    ans = 10**18
    for a,b in ret:
        ans = min(a+b, ans)
    print(ans-2)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
res = 10**12
for i in range(1,math.ceil(math.sqrt(n))):
  if n%i==0:
    res = min(res,i+n//i-2)
print(res)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())

    ans = 10 ** 18
    i = 1
    while i * i < N:
        if N % i == 0:
            j = N // i
            ans = min(ans, i+j-2)
        i += 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
res = 10**9+7
for i in range(1,math.ceil(math.sqrt(n))):
  if n%i==0:
    res = min(res,i+n//i-2)
print(res)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    
    if is_prime(N):
        print(N-1)
        sys.exit()
        
    ll = factorize(N)
    ll.sort()
    
    #print(ll)
    
    if len(ll) == 2:
        a = ll[0] -1
        b = ll[1] -1
        print(a + b)
        sys.exit()
    
    ans = []
    while True:
        if len(ll) %2 == 1:
            for i in range(len(ll)//2):
                tmptmp = (-1 * i) + -1
                tmp = ll[i] * ll[tmptmp]
                ans.append(tmp)
            tmp = ll[(len(ll)//2)+1]
            ans.append(tmp)
            
        else:
            for i in range(len(ll)//2):
                tmptmp = (-1 * i) + -1
                tmp = ll[i] * ll[tmptmp]
                #print(tmp)
                ans.append(tmp)
                
        if len(ans) == 2:
            break
        else:
            ll = ans
            ll.sort()
        
    #print(ans)
    a = ans[0] -1
    b = ans[1] -1
    print(a + b)
    
def is_prime(n): 
    i = 2
    while i * i <=n:
        if n % i == 0:
            return False
        i += 1
    return True
    
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct
    
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

n = int(input())
x = []
for i in range(1,math.ceil(math.sqrt(n))):
    if(n%i == 0):
        x.append(i+n/i-2-0)
print(round(min(x)))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

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

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
sqrtN = int(math.sqrt(N))

candidate = N - 1

for i in range(2, sqrtN):
    if not N % i:
        if N // i + i - 2 < candidate:
            candidate = N // i + i - 2
print(candidate)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
sqrtN = int(math.sqrt(N))

candidate = N - 1

for i in range(1, sqrtN):
    if not N % i:
        if N // i + i - 2 < candidate:
            candidate = N // i + i - 2
print(candidate)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
sqrtN = int(math.sqrt(N))

candidate = N

for i in range(1, sqrtN):
    if not N % i:
        if N // i + i - 2 < candidate:
            candidate = N // i + i - 2
print(candidate)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    
    if is_prime(N):
        print(N-1)
        sys.exit()
        
    ll = factorize(N)
    ll.sort()
    
    if len(ll) == 2:
        a = ll[0] -1
        b = ll[1] -1
        print(a + b)
        sys.exit()
    
    ans = []
    while True:
        if len(ll) == 2:
            break
            
        tmp = ll[0] * ll[1]
        ll.pop(0)
        ll.pop(1)
        ll.append(tmp)
        ll.sort()
        
    a = ll[0] -1
    b = ll[1] -1
    print(a + b)
    
def is_prime(n): 
    i = 2
    while i * i <=n:
        if n % i == 0:
            return False
        i += 1
    return True
    
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct
    
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
maxn = math.ceil(math.sqrt(n))
res1=1
for i in range(2,maxn):
    if n % i == 0:
        res1 = i

print(res1 + (n // res1)-2)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

sqrtN = int(math.sqrt(N))

for i in reversed(range(1, sqrtN)):
    if N % i == 0:
        print(int(i + N/i - 2))
        quit(0)

Submission status: Wrong Answer

Solution code:
n = int(input())

result = float("INF")
#print(n/2)
#print(int(n/2))
for i in range(1, int(n/2)+1):
    for j in range(1, int(n/2)+1):
        if i * j == n:
            #print(i)
            #print(j)
            result = min(result, i+j-2)
print(result)

Submission status: Wrong Answer

Solution code:
import math

def sq(n):
    for i in range(math.ceil(math.sqrt(N)), -1, -1):
        print(i)
        if n % i == 0:
            return (i, n//i)

N = int(input())
a, b = sq(N)
print(a + b - 2)

Submission status: Wrong Answer

Solution code:
import math

def sq(n):
    for i in range(math.floor(math.sqrt(N)), 0, -1):
        print(i)
        if n % i == 0:
            return (i, n//i)

N = int(input())
a, b = sq(N)
print(a + b - 2)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
ans=n+1
i=1
while i<=math.sqrt(n):
    if n%i==0:
        ans = n%i + n/i
        i+=1
print(ans-2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

ans  = 10 ** 12 
for i in range(1, math.floor(math.sqrt(n)) + 1):
    if n%i != 0:
        continue
    j = n/i
    ans = min(ans, i+j-2)

print(ans)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

ans  = 10 ** 7 
for i in range(1, math.floor(math.sqrt(n)) + 1):
    if n%i != 0:
        continue
    j = n/i
    ans = min(ans, i+j-2)

print(ans)

Submission status: Wrong Answer

Solution code:
# C - Walk on Multiplication Table
n = (int)(input())

minimum = 1e18
i = 1
while(i*i < n):
    if n % i != 0:
        i += 1
        continue;
    j = (int) (n / i)
    minimum = min(i + j - 2, minimum)
    i +=1

print(minimum)

Submission status: Wrong Answer

Solution code:
# C - Walk on Multiplication Table
n = (int)(input())

minimum = 1e18
i = 1
while(i*i < n):
    if n % i == 0:
        j = (int) (n / i)
        minimum = min(i + j - 2, minimum)
    i +=1

print(minimum)

Submission status: Wrong Answer

Solution code:
# C - Walk on Multiplication Table
n = (int)(input())

minimum = 1e18
for i in range(1, (int)(n ** 0.5)):
    if n % i == 0:
        minimum = (int)(min(i + n / i - 2, minimum))

print(minimum)

Submission status: Wrong Answer

Solution code:
from math import sqrt
n = int(input())
ans = 0


for i in range(1,round(sqrt(n))):
    if n % i == 0:
        
      if ans == 0:
        ans = i + n/i
      else:
        ans = min(ans, i + n/i)
        

print(round(ans -2))

Submission status: Wrong Answer

Solution code:
pf = []
power = []

def PF(pf, power, n):
    i = 2
    while (i * i <= n):
        if n % i == 0:
            pf.append(i)
            j = 1
            count = 0
            while (n % (i ** j) == 0):
                n = n / (i ** j)
                count += 1
            power.append(count)
        i += 1
    if n != 1:
        pf.append(int(n))
        power.append(1)

def dist(pf, power):
    A = 1
    B = 1
    n = len(pf)
    for i in range(n):
        j = power[i]
        while j > 0:
            if A < B:
                A *= pf[i]
            else:
                B *= pf[i] 
            j -= 1
    return (A - 1) + (B - 1)

N = int(input())
PF(pf, power, N)
print(dist(pf, power))

Submission status: Wrong Answer

Solution code:
#
# abc144 c
#
import unittest
from io import StringIO
import sys
import math


def input():
    return sys.stdin.readline().rstrip()


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

    S = math.ceil(math.sqrt(N))
    ans = N - 1

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


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[: -1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """10"""
        output = """5"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """50"""
        output = """13"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """10000000019"""
        output = """10000000018"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Wrong Answer

Solution code:
# C - Walk on Multiplication Table
n = (int)(input())

flg = False

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

print(minimum)