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

import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
N = I()

ans = int(0)
cou = []

cou = make_divisors(N)

ans = cou[-1]+cou[-2]-2


#print(cou)
print(ans)

Submission status: Wrong Answer

Solution code:
a = int(input())

b = []
for i in range(2,int(-(-a**0.5//1))+1):
    if a % i ==0:
        b.append(i)
        a = a/i
        while a%i==0:
            b.append(i)
            a = a/i
if a != 1:
    b.append(a)
if b == []:
    b.append(a)

if len(b)==1:
    print(b[0]-1)
elif len(b)==2:
    print(int(b[0]+b[1]-2))
else:
    r = b[-1]
    s = b[-2]
    for j in range(2,len(b)):
        i = -1-j
        if r>s:
            s = s*b[i]
        else:
            r = r * b[i]
    print(r+s-2)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

soinsu = prime_factorize(n)


soinsu.sort()
if len(soinsu) ==1:
    print(soinsu[0]-1)
    
else:
    right = soinsu[-1]
    left = soinsu[-2]


    for i in range(len(soinsu)-2):
        if i == 0:
            right *= soinsu[i]
        elif i % 2 != 0:
            right *= soinsu[i]
        elif i % 2 == 0:
            left *= soinsu[i]
    ans = right + left -2
    minimum = abs(left-right)

    right = soinsu[-1]
    left = soinsu[-2]

    for i in range(len(soinsu)-2):
        if i == 0:
            left *= soinsu[i]
        elif i % 2 != 0:
            left *= soinsu[i]
        elif i % 2 == 0:
            right *= soinsu[i]

    if abs(left-right) < minimum:
        print(left + right -2)
    else:
        print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    x = int(input())
    ans = 15000
    for i in range(x, 0, -1):
        if x % i == 0:
            q = (int(x/i) - 1) + (i-1)
            if q < ans:
                ans = q
            else:
                print((int(x/i) - 1) + (i-1))
                break

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a = 0
b = 0
ans = 0
for i in range(int(math.sqrt(n)),1,-1):
  print(i)
  a = i
  b = n/i
  if b%1 == 0 and b<10:
    ans = a+b-2
    break
print(a,b,ans)

Submission status: Wrong Answer

Solution code:
a=int(input())
for i in range(a):
    p=a/(i+1)
    if (i+1)>=p and p%1==0:
        break
print(i+p-1)

Submission status: Wrong Answer

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

n=int(input())
m=prime_factorize(n)
M=m[::-1]
#print(m)
if m==[n]:print(n-1)
else:
    a=1;b=1;c=1;d=1
    for i in m:
        if a<=b:
            a*=i
        else:
            b*=i
    #print(a,b)
    for i in M:
        if c<=d:
            c*=i
        else:
            d*=i
    #print(a,b,c,d)
    s=len(m)
    e=1;f=1
    for i in range(s//2+1):
        e*=m[i]
    f=n//e
    print(min(a+b-2,c+d-2,e+f-2))

Submission status: Wrong Answer

Solution code:
N = 10000000019  # int(input())


def prime_decomposition(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


def solve(N):
    list_N = prime_decomposition(N)
    ans = N - 1
    for i in list_N:
        ans_tmp = ((N / i) - 1) + (i - 1)
        if ans > ans_tmp:
            ans = ans_tmp

    return ans


print(solve(N))

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from itertools import permutations, combinations,combinations_with_replacement,product
from fractions import Fraction as frac
import bisect
import heapq

import logging
logging.basicConfig(level=logging.DEBUG)

import sys
#input = sys.stdin.readline().rstrip

setrecursionlimit(1000000)

MOD = 10**9+7
INF = float('inf')

def main():
    N=int(input())
    l=sorted(divisor(N))
    # print(l)

    j=len(l)//2
    i=j-1
    print(l[i]-1 + l[j]-1)

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

main()

Submission status: Wrong Answer

Solution code:
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__":
    N = int(input())

    div = factorize(N)
    div.reverse()

    A, B = 1, 1

    ans = 0
    for i in div:
        ans += i

    print(ans-2)

Submission status: Wrong Answer

Solution code:
target = int(input())
possibleI = []
possibleAns = []

for i in range(1,10):
  if target % i == 0:
    possibleI.append(i)

for i in possibleI:
  j = target // i
  possibleAns.append(j+i-2)

print(min(possibleAns))

Submission status: Wrong Answer

Solution code:
def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    table.sort()
    return table

N = int(input())

n = []
n = divisor(N)

cnt = 999999999999999
for i in range(0,len(n)//2,1):
    t = int(n[i])-1 + int(n[len(n)-i-1])-1
    if n[i] == 1:
        t += 1
    if n[len(n)-i-1] == 1:
        t += 1
    if cnt > t:
        cnt = t
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
import sys

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

for i in range(round(math.sqrt(N))):
  j = i + 1
  if N % j == 0:
    if a > j - 1 + N / j - 1:
      a = j - 1 + N / j - 1
print(a)

Submission status: Wrong Answer

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)
divisors.sort()
#print(divisors)

l = len(divisors)
if l % 2 == 0:
    a = divisors[:int(l/2)]
    b = divisors[int(l/2):]
    b.sort(reverse=True)
    c = []
    for i in range(int(l/2)):
        c.append(a[i]+b[i])
    print(min(c)-2)
        
else:
    a = divisors[:int(l/2)]
    b = divisors[int((l+1)/2):]
    b.sort(reverse=True)
    c = divisors[int((l+1)/2)]
    d = []
    for i in range(int((l-1)/2)):
        d.append(a[i]+b[i])
    print(min(min(d), c*2) - 2)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

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

l = factorization(n)

x = 1
y = n
ans = []

for i in range(len(l)):
	for j in range(l[i][1]):
		x *= l[i][0]
		y /= l[i][0]
		ans.append(x+y)

print(int((min(ans)-2)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

factor = []

tmp = int(math.sqrt(N)) + 1
for num in range(2,tmp):
    while N % num == 0:
        N //= num
        factor.append(num)

factor.append(N)

A=1
B=1
for i in range(len(factor)):
    if i % 2 == 0:
        A *= factor[i]
    else:
        B *= factor[i]

print(A+B-2)

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

N = int(input())
list =make_divisors(N)
list_rev=sorted(list, reverse=True)

ans = 10**9
for i in range(len(list)//2 + 1):
  tmp = (list[i]-1)+(list_rev[i]-1)
  if tmp < ans:
    ans=tmp

print(ans)

Submission status: Wrong Answer

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

l = list(reversed(prime_factorize(N)))
A=1
B=1
for i in l:
    if A<B:
        A*=i
    else:
        B*=i

print(A+B-2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import random

def miller_rabin(n, k=20):
    n = abs(n)
    if n == 2:
        return True
    elif n == 1 or n & 1 == 0:
        return False
    d = n - 1
    while d & 1 == 0:
        d = d >> 1
    for i in range(k):
        a = random.randint(1, n - 1)
        t = d
        y = pow(a, t, n)
        while t != n - 1 and y != 1 and y != n - 1:
            y = pow(y, 2, n)
            t = t << 1
        if y != n - 1 and t & 1 == 0:
            return False
    return True

i = int(input())

if miller_rabin(i):
    print(i - 1)

minimum = pow(10, 12)
for x in range(1, i + 1):
    tmp = i / x
    if tmp.is_integer() is not True:
        continue
    if tmp == 1:
        continue
    if tmp + x < minimum:
        minimum = tmp + x

print(int(minimum) - 2)

Submission status: Wrong Answer

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)
divisors.sort()
#print(divisors)

l = len(divisors)
if l % 2 == 0:
    a = divisors[:int(l/2)]
    b = divisors[int(l/2):]
    b.sort(reverse=True)
    c = []
    for i in range(int(l/2)):
        c.append(a[i]+b[i])
    print(min(c)-2)
        
else:
    a = divisors[:int(l/2)]
    b = divisors[int((l+1)/2):]
    b.sort(reverse=True)
    c = divisors[int((l+1)/2)]
    d = []
    for i in range(int((l-1)/2)):
        d.append(a[i]+b[i])
    print(min(min(d), c) - 2)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

X = prime_factorize(N)
#print(X)

res = 1000000000000
for i in X:
    b = int(N/i)
    if res > i + b:
        res = i + b

print(res-2)

Submission status: Wrong Answer

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

N = int(input())

prime_N = factorization(N)
prime_N = sorted(prime_N, reverse=True, key=lambda x: x[0])
A = 1
B = 1
for i in range(len(prime_N)):
    for j in range(prime_N[i][1]):
        if A <= B:
            A *= prime_N[i][0]
        else:
            B *= prime_N[i][0]

#print(A, B)
print(A + B - 2)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

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

l = factorization(n)
print(l)
x = 1
y = n
ans = []

for i in range(len(l)):
	for j in range(l[i][1]):
		x *= l[i][0]
		y /= l[i][0]
		ans.append(x+y)

print(int((min(ans)-2)))

Submission status: Wrong Answer

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
            for j in range(1,cnt+1):
              arr.append(n/(i**j)+i**j-2)

    if temp!=1:
        arr.append(n/temp+temp-2)

    
    arr.append(n/1+1-2)

    return arr
  
N = int(input())
A = factorization(N)
print(int(min(A)))

Submission status: Wrong Answer

Solution code:
N = int(raw_input())

def factor(x):
    result = []
    d = 2
    while x >= d:
        quot, rem = divmod(x, d)
        if rem:
            d += 1
        else:
            result.append(d)
            x = quot
    return result

def compose(xs):
    if len(xs) <= 1:
        return xs + [1]
    if len(xs) == 2:
        return xs
    return compose([xs[0] * xs[1]] + xs[2:])

factors = factor(N)
i, j = compose(factors)
print (i - 1) + (j - 1)

Submission status: Wrong Answer

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

n=int(input())
#n=factorization(10**9+7) 
x=factorization(n)
y=[]
for i in x:
    y+=[i[0]]*i[1]
if len(y)==1:
    print(y[0]-1)
else:
    a=b=1
    while len(y)>2:
        y.sort(reverse=True)
        a=y.pop()
        b=y.pop()
        y.append(a*b)
    print(y[0]+y[1]-2)

Submission status: Wrong Answer

Solution code:
def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    table.sort()
    return table

N = int(input())

n = []
n = divisor(N)

cnt = 999999999999999
for i in range(0,len(n)//2,1):
    t = int(n[i])-1 + int(n[len(n)-i-1])-1
    if cnt > t:
        cnt = t
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
mi = 1000
mi1 = 0
mi2 = 0
for i in range(1,n+1):
	q = n // i
	mod = n % i
	if mod == 0:
		if mi > abs(q - i):
			mi = abs(q-1)
			mi1 = i
			mi2 = q
print(mi1+mi2-2)

Submission status: Wrong Answer

Solution code:
n = int(input()) 

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

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



n = int(input())

tmp = make_divisors(n)

num0 = tmp[len(tmp) // 2 - 1]
num1 = tmp[len(tmp) // 2]


print(str(num0 + num1 - 2))

Submission status: Wrong Answer

Solution code:
def main():
    nn = n = input()
    if n == 1:
        print(0)
        return
    factors = []
    p = 2
    while n % p == 0:
        factors.append(p)
        n //= p
    p = 3
    while nn >= p * p:
        while n % p == 0:
            factors.append(p)
            n //= p
        p += 2
    if n > 1:
        factors.append(n)

    a = b = 1
    for f in factors[::-1]:
        if a > b:
            b *= f
        else:
            a *= f
    print(a + b - 2)

main()

Submission status: Wrong Answer

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

n = int(input())

fac = factorization(n)
if len(fac) == 1:
	print(fac[0]-1)
	exit()
a=1
b=1
c = 0
for i in range(len(fac)//2):
	if c % 2 == 0:
		a *= fac[2*i]
		b *= fac[2*i+1]
	else:
		a *= fac[2*i+1]
		b *= fac[2*i]
	c+=1
if len(fac)%2 == 1:
	a *= fac[i]
print("%d" % (a+b-2))

Submission status: Wrong Answer

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

l = list(reversed(prime_factorize(N)))
A=1
B=1
for i in range(len(l)):
    if A<B:
        A*=l[i]
    else:
        B*=l[i]

print(A+B-2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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__":
    N = int(input())

    div = factorize(N)
    div.reverse()

    A, B = 1, 1

    for i in range(len(div)):
        tmp = div[i]
        if A * tmp + B <= A + B * tmp:
            A *= tmp
        else:
            B *= tmp

    print(A+B-2)

Submission status: Wrong Answer

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

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

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

    return arr



n = int(input())

g = factorization(n)
f = []
for x in g:
    for y in range(1,x[1]+1):
        f.append(x[0])

#print(f)
f.sort()
#print(f)
dex = len(f) - 1
a = 1
b = 1
#print(dex)
while dex >= 0:
    if dex < 0:
        break
    else:
        a *= f[dex]
        dex -= 1
    if dex < 0:
        break
    else:
        b *= f[dex]
        dex -= 1

print(a+b-2)

Submission status: Wrong Answer

Solution code:
import math

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

if N == 2 or N == 3:
    print(N-1)
elif sq*sq == N:
    print(2*sq-2)
else:
    for i in reversed(range(1,sq)):
        if N % i == 0:
            print(i+(N//i)-2)
            break

Submission status: Wrong Answer

Solution code:
def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    table.sort()
    return table

N = int(input())

n = []
n = divisor(N)
print(n)

cnt = 999999999999999
if len(n) >= 2:
    for i in range(0,len(n)//2,1):
        t = int(n[i])-1 + int(n[len(n)-i-1])-1
        if cnt > t:
            cnt = t
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []
minP = N

for i in range(1, int(N/2)+1):
    if N % i == 0:
        A.append(i)
        B.append(int(N / i))
if len(A) == 2:
    print(N-1)
for i in range(0, len(A)):
    if minP > A[i] + B[i]:
        minP = A[i] + B[i]
print(minP-2)

Submission status: Wrong Answer

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

N = int(input())

ele_l = factorization(N)
new_ele_l = []
for ele in ele_l:
    new_ele_l.extend([ele[0]]*ele[1])

if(len(new_ele_l)<2):
    new_ele_l.append(1)
#print(ele_l)
#print(new_ele_l)
while(len(new_ele_l)>2):
    update_ele = new_ele_l[0]*new_ele_l[1]
    new_ele_l = new_ele_l[2:]
    #print(new_ele_l)
    new_ele_l.append(update_ele)
    new_ele_l = sorted(new_ele_l)
    #print(new_ele_l)

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

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

ans = 99999999999999999
cnt = 99999999999999999

for i in range(1, math.ceil(n/2)):
  for j in range(math.floor(n/2), 1, -1):
    if i * j == n:
      cnt = i + j -2
      ans = min(cnt, ans)

print(ans)

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)

    result = sorted(divisors)
    if len(result) == 2:
        final_i = result[0]
        final_j = result[1]
    else:
        if len(result)%2 == 0:
            final_i = result[len(result)//2]
            final_j = result[len(result)//2 - 1]
            
        else:
            final_i = result[(len(result)+1)//2]
            final_j = result[(len(result)+1)//2]
                 
    return final_i+final_j - 2

make_divisors(N)

Submission status: Wrong Answer

Solution code:
import math
import sys

N = int(input())
a = 0

for i in reversed(range(round(math.sqrt(N)))):
  j = i + 1
  if N % j == 0:
    print(j - 1 + N / j - 1)
    sys.exit()

Submission status: Wrong Answer

Solution code:
from scipy.spatial.distance import cityblock

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():
  N = int(input())
  x = make_divisors(N)
  ans = []
  for i in range(int(len(x)/2)):
    ans.append(cityblock((1,1),(x[i],x[len(x)-1-i])))
  print(min(ans))

main()

Submission status: Wrong Answer

Solution code:
N = int(input())

judge = False
A = 1
B = 1

for i in range(1,N+1,1):
    for j in range(1,N+1,1):
        if i*j == N:
            judge = True
            A = i
            B = j
            break
    if judge:
        break


print(A+B-2)

Submission status: Wrong Answer

Solution code:
N=int(input())

def divisors(a):
	divisors=[]
	for i in range(1,int(a**0.5)+1):
		if a%i==0:
			divisors.append(i)
			if i!=a//i:
				divisors.append(a//i)
	divisors.sort() # 昇順
	# divisors.sort(reverse=True) # 降順
	return divisors

d=divisors(N)
l=len(d)
if l%2==0:
  a=d[int(l/2)]+d[int(l/2-1)]
else:
  a=d[int((l-1)/2)]
print(a-2)

Submission status: Wrong Answer

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

l = prime_factorize(N)
A=1
B=1
for i in range(len(l)):
    if A<B:
        A*=l[i]
    else:
        B*=l[i]

print(A+B-2)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

ans = 999999999999
cnt = 0

for i in range(1, math.ceil(n/2)):
  for j in range(math.floor(n/2), 1, -1):
    if i * j == n:
      cnt = i + j -2
      ans = min(cnt, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

min = float('inf')
for i in range(0, len(cd) - 1,  2):
    if cd[i] + cd[i+1] < min:
        min = cd[i] + cd[i+1]

print(min - 2)

Submission status: Wrong Answer

Solution code:
n = int(input())

res = 10**20
for i in range(1,10**6):
    if n%i == 0:
        res = min(res,i+n//i)
print(res-2)

Submission status: Wrong Answer

Solution code:
a = int(input())

b = []
for i in range(2,int(-(-a**0.5//1))+1):
    if a % i ==0:
        b.append(i)
        a = a/i
        while a%i==0:
            b.append(i)
            a = a/i
if a != 1:
    b.append(a)
if b == []:
    b.append(a)

if len(b)==1:
    print(b[0]-1)
elif len(b)==2:
    print(int(b[0]+b[1]-2))
else:
    r = b[0]
    s = b[1]
    for i in range(2,len(b)):
        if r>s:
            s = s*b[i]
        else:
            r = r * b[i]
    print(r+s-2)

Submission status: Wrong Answer

Solution code:
N=int(input())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
sosu=prime_factorize(N)
A=sosu[0::2]
B=sosu[1::2]
AA=1
BB=1
for a in A:
    AA*=a
for b in B:
    BB*=b
print(int(AA+BB-2))

Submission status: Wrong Answer

Solution code:

if __name__ == '__main__':
    N = int(input())
    res = N
    for i in range(2, N):
        for j in range(1, i//2+1):
            if (i-j) * j == N:
                res = min(res, (i-2))
                continue
    print(res)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

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

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

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

    return arr

N = int(input())

res = factorization(N)

if len(res) == 0:
    print(0)
elif len(res) == 1:
    print(N-1)
elif len(res) == 2 and res[0][1] == 1 and res[1][1] == 1:
    print(res[0][0] + res[1][0] - 2)
else:
    tmp1 = 1
    tmp2 = 1
    for pair in res:
        for _ in range(pair[1]):
            if tmp1 < tmp2:
                tmp1 *= pair[0]
            else:
                tmp2 *= pair[0]
    print(tmp1 + tmp2 - 2)

Submission status: Wrong Answer

Solution code:
N=int(input())
c=0
INF=2000000
x=[0 for _ in range(INF)]
y=[0 for _ in range(INF)]

for i in range(N):
    if i*i>N : break
    for j in range(N-(i+1)) :
        if (i+1)*(j+1)==N:
            x[c]=i
            y[c]=j
            c+=1

d=INF
for i in range(c):
    if d>(x[i]+y[i]):
        d=x[i]+y[i]

print(d)

Submission status: Wrong Answer

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)
            # arr.append([i, cnt])

    if temp!=1:
        arr.append(temp)

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

    return arr

n = int(input())
factList = factorization(n)

max = 10 ** 13
if len(factList) == 1 :
    print(factList[0] - 1)
    exit()
factList = sorted(factList, reverse=True)
#print(factList)
pair = [1, 1]
for i in range(len(factList)) :
    if pair[0] <= pair[1] :
        pair[0] *= factList[i]
    else :
        pair[1] *= factList[i]
#print(pair)
print(sum(pair) - 2)

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)

    # divisors.sort()
    return divisors

tmp = make_divisors(N)
print(tmp[-1] + tmp[-2] - 2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
for i in reversed(range(int(math.sqrt(N)))):
    if N%(i+1)==0:
        print(N//(i+1)+i+1)
        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:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

from math import sqrt
N = int(input())
a = make_divisors(N)
print(a)

l = len(a)
if (l%2 == 0):
    print(a[-1] + a[-2] - 2)
else:
    print(a[-1]*2 - 2)

Submission status: Wrong Answer

Solution code:
words = lambda t : list(map(t, input().split()))
n = int(input())


import math
def prime_factors(n):
    pfs = []
    m = int(math.sqrt(n)) + 1
    for num in range(2,m):
        if n % num == 0:
            while n % num == 0:
                n //= num
                pfs.append(num)
    if not n == 1:
        pfs.append(n)
    return pfs

pfs = prime_factors(n)
#print(pfs)

pfs = reversed(sorted(pfs))
x = 1
y = 1
for pf in pfs:
    if x * pf + y <= y * pf + x:
        x *= pf
    else:
        y *= pf
print(x + y - 2)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = n - 1
for c in range(2, int(n ** 0.5)):
    if n % c == 0:
        w = int(n / c)
        if (w + c - 2) < a:
            a = (w + c -2)
        else:
            continue
    else:
        continue
print(a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

# コピー
m = 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)

ans = 0

if len(a) == 1:
  ans = a[0] - 1
else:
  x = a[-1]
  y = m // x
  ans = x- 1 + y -1

print(ans)

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

a = int(input())
b = make_divisors(a)
if len(b) % 2 == 0:
  idx = len(b) // 2
  target = (b[idx],b[idx-1])
else:
  idx = len(b) // 2
  target = (b[idx-1],b[idx+1])
print(target[0]-1 + target[1]-1)