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:
import sys

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

stdin = sys.stdin

ni = lambda: int(ns())
ns = lambda: stdin.readline()

N = ni()
ans = 0
if N > 1:
    div = divisor(N)
    print(div, div[len(div)//2 - 1])
    if len(div) > 1:
        i = div[len(div)//2 - 1] - 1
        j = (N // (div[(len(div)//2) - 1]))  - 1
        ans = i + j
    else:
        ans = 1
elif N == 1:
    ans = 0
else:
    ans = 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


# def factorization(n):
#     factor = []
#     tmp = int(math.sqrt(n)) + 1
#     for i in range(2, tmp):
#         while n % i == 0:
#             n //= i
#             factor.append(i)
#         if len(factor) != 0:
#             factor.append(n)
#             return factor
#     return []


def solve(inputs):
    N = int(inputs[0])
    # factors = factorization(N)
    min_diff = None
    for i in range(1, 1000000):
        if N % i == 0:
            a = N // i
            diff = a + i - 2
            print(a, i, diff)
            if min_diff is None or min_diff > diff:
                min_diff = diff
    return min_diff


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [1]
while not n%2:
   n//=2
   a.append(2)
i = 3
while i*i<=n:
    while not n%i:
        n//=i
        a.append(i)
    i+=2
if n>1:
    a.append(n)
c,d = 1,1
for i in range(len(a)):
    if c*a[i]<=d*a[i]:
        c*=a[i]
    else:
        d*=a[i]
print(c+d-2)

Submission status: Wrong Answer

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


fact = factorization(n)

ans = 0

max_y = fact[-1][0]
ans = max_y + n // max_y - 2
print(ans)

Submission status: Wrong Answer

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


tuple_list = []
for i in range(2, int((N+1)/2)):
    if N % i == 0:
        tuple_list.append((i, int(N / i)))

#print(tuple_list)
sum = 10 **12 +1
for i,j in tuple_list:
    #print(i)
    if sum > i + j:
        sum = i + j
print(sum -2)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
move = n-1
m = math.ceil(n ** (1/2))
for i in range(1, (m+1)):
    for j in range(1, (m+1)):
        if n == i*j and move > i+j-2:
            move = i+j-2
        else:
            move += 0
print(move)

Submission status: Wrong Answer

Solution code:
import random
import math
def is_prime(q, k=50):
    q = abs(q)
    if q == 2:
        return True
    if q < 2 or q % 2 == 0:
        return False

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


n = int(input())
if is_prime(n)== True:
    print(n-1)
else:
    m = 10000000
    for i in range(2, int(math.sqrt(n))):
        if n%i==0:
            temp = n//i
            if temp+i < m:
                m = temp+i
    print(m-2)

Submission status: Wrong Answer

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

for i in range(int(math.sqrt(n)), 2, -1):
    if n % i != 0:
        continue
    else:
        if tmp > (n//i)+(i)-2:
            tmp = (n//i)+i-2
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(n // i + i)
            if i != n // i:
                print(n // i, i)
                divisors.append(n // i + i)
    divisors.sort()
    return divisors


def main():
    n = int(input())
    divs = make_divisors(n)
    res = divs[0]

    print(res - 2)


if __name__ == '__main__':
    main()

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
print(make_divisors(N)[-1]+make_divisors(N)[-2]-2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

A = int(input())

v = 10000000000000
for i in range(A // 2):
    x = i + 2
    if A % x > 0:
        continue
    n = x + A // x - 2
    if v > n:
        v = n
    else:
        break
print(n)

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)

    if arr==[]:
        arr.append(n/1+1-2)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

elms = prime_factorize(n)
if len(elms) == 1:
  print(elms[0]-1)
  sys.exit()
else:
  a = elms.pop(0)
  b = elms.pop(0)
  turn = 1
  while len(elms) > 0:
    if turn>0:
      a *= elms.pop(0)
      turn *= -1
    else:
      b *= elms.pop(0)
      turn *= -1

print(a+b-2)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
rN = math.ceil(math.sqrt(N))
rN = int(rN)
li = []
if N == 1:
    print("0")
    exit()
for i in range(1,rN):
    if N % i == 0:
        li.append( i +(N//i))
print(min(li)-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(AA+BB-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)

    return divisors

N = int(input())

combo = make_divisors(N)
combo = [sum(combo[i:i+2]) for i in range(0,len(combo),2)]
combo = min(combo) - 2

print(combo)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

from collections import deque

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

N = int(input())
A_tmp = deque(prime_factorize(N))
N_tmp, N_tmp1, N_tmp2= 0, 1, 1
A_len = len(A_tmp)
counter = 1

while True:
    if A_tmp == deque([]):
        break
    else:
        if counter % 2 == 1:
            N_tmp = A_tmp.popleft()
        else:
            N_tmp = A_tmp.pop()
        if N_tmp1 >= N_tmp2:
            N_tmp2 = N_tmp * N_tmp2
        else:
            N_tmp1 = N_tmp * N_tmp1
    counter += 1
print(N_tmp1 + N_tmp2 - 2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
def yks(n):
    yakusu = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            yakusu.append(i)
            if i != n // i:
                yakusu.append(n//i)
    yakusu.sort()
    return yakusu
g=yks(n)
p=len(yks(n))//2
print(g[p]+g[p-1]-2)

Submission status: Wrong Answer

Solution code:
N = int(input())

def prime_factorize(num):
    """
    This function performs prime factorization on the input natural number.
    The result is returned in the form of a dictionary with the prime number as the key
    and its number as the value.
    :param num:
    :return prime_factor: Dictionary with the prime number as the key and its number as the value.
    """
    prime_factor = {}
    i = 2
    while i ** 2 <= num:
        while num % i == 0:
            num //= i
            if i in prime_factor.keys():
                prime_factor[i] += 1
            else:
                prime_factor[i] = 1
        i += 1
    if num > 1:
        prime_factor[num] = 1
    return prime_factor

res = prime_factorize(N)

tar = []

for k, v in res.items():
    for j in range(v):
        tar.append(k)
tar.sort()
x = 1
y = 1

for i in range(len(tar)):
    if i % 2 == 0:
        x *= tar[i]
    else:
        y *= tar[i]
print(x + y - 2)

Submission status: Wrong Answer

Solution code:
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:
                arr.append(i)
                temp //= i   
    if temp!=1:
        arr.append(temp)
    if arr==[]:
        arr.append(n)
    return arr

facro = factorization(N)

if len(facro) == 1:
    print(facro[0] -1)
else:
    facro_len = len(facro)

    min_map = [facro[0],facro[1]]

    min_count = 0
    while 2 != (facro_len - min_count):
        if min_map[1] >= min_map[0]:
            min_map[0] = min_map[0]*facro[min_count +2]
        else:
            min_map[1] = min_map[1]*facro[min_count +2]
        min_count += 1

    print(min_map[0] +min_map[1] -2)

Submission status: Wrong Answer

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

yaku = []

for i in range(1, int(math.sqrt(N))):
    if N%i==0:yaku.append([i, N//i])

ab=N

for a, b in yaku:
    ab = min(ab, a+b-2)

print(ab)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

a = int(N**0.5)
b = a+1

res = []
for i in range(1,a):
  if N%i == 0:
    res.append([i, int(N/i)])
    
ans = 10**12 + 10
for i in range(len(res)):
  ans = min(ans, sum(res[i]))
  
if N == 1:
  print(0)
elif N == 2:
  print(1)
elif N == 3:
  print(2)
else:
  print(ans-2)

Submission status: Wrong Answer

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

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())
divisors = make_divisors(n)
divisors.sort()
res = n*2
for i in range(int(len(divisors)/2)):
	if res > (divisors[i]+divisors[-(i+1)]-2):
		res = (divisors[i]+divisors[-(i+1)]-2)
print(res)

Submission status: Wrong Answer

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

tmp = factorization(n) 

f_list = []
for one in tmp:
    for i in range(one[1]):
        f_list.append(one[0])
        
        
size = len(f_list)
a = 1
b = 1
for i in range(size):
    num = f_list.pop(size-i-1)
    if i == 0:
        a =num
    else:
        if abs(a *num - b) > abs(b*num-a):
            b *=num
        else:
            a *= num
print(a+b-2)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
N = int(input())

first_num = 0
second_num = 0
min_diff = N
for i in range(1, int(np.sqrt(N))):
    now_diff = N // i - i
    if N % i == 0 and min_diff > now_diff:
        first_num = i
        second_num = N // i
        min_diff = now_diff
print(max(first_num + second_num - 2, 0))

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())
a = (make_divisors(n))
sa = 10000000000
p = -1
mid = n/2
for i in a[:int(n/2)+1]:
  if(abs(i-sa) > mid):
    sa = abs(i-sa)
    p = i
print(p+int(n/p)-2)

Submission status: Wrong Answer

Solution code:
x = int(input())
import math
list = []
half = math.ceil(math.sqrt(x))
for i in reversed(range(half)):
    if x % i == 0:
        print(int(i + x/i - 2))
        break

Submission status: Wrong Answer

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

#a, b, c, d = (int(i) for i in input().split())
#a = [int(i) for i in input().split()]


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

#print(factorization(11))

N = int(input())
nfactor = [1, 1]
nfactorindex = 0

arr = []
temp = N

#print(int(-(-N**0.5//1))+1)

for i in range(2, int(-(-N**0.5//1))+1):
    #print(nfactor)
    if temp%i==0:
        cnt= 0
        while temp%i==0:
            cnt+=1
            temp //=i
            nfactor[nfactorindex] = nfactor[nfactorindex] *i
            nfactorindex = (nfactorindex+1)%2
        arr.append([i, cnt])

if temp!=1:
    arr.append([temp, 1])
    nfactor[nfactorindex] = nfactor[nfactorindex] *temp
if arr==[]:
    arr.append([n, 1])
    nfactor[nfactorindex] = nfactor[nfactorindex] *N

#print(nfactor)

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

Submission status: Wrong Answer

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

tmp = factorization(n) 

f_list = []
for one in tmp:
    for i in range(one[1]):
        f_list.append(one[0])
        
print(f_list)
        
size = len(f_list)
a = 1
b = 1
for i in range(size):
    num = f_list.pop(size-i-1)
    if i == 0:
        a =num
    else:
        if abs(a *num - b)> (b*num-a):
            b *=num
        else:
            a *= num
print(a,b)
print(a+b-2)

Submission status: Wrong Answer

Solution code:
import sys
import math

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

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

print(ls)

print(min(a[0] + a[1] -2 for a in ls))

Submission status: Wrong Answer

Solution code:
from functools import reduce
from operator import mul

N = int(input())

def main():
    primes = prime_factorize(N)
    if len(primes) == 1:
        print(primes[0] - 1)
        return
    print((primes[-1] - 1) + (reduce(mul, primes[0:-1]) - 1))
    
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

main()

Submission status: Wrong Answer

Solution code:
N=int(input()); j=N
a,b=0,0
for dx in range(0,10000):
    i=1+dx
    tmp=N//i
    if i*tmp==N and (dx+tmp)<(a+j):
        j=tmp; a=dx
print(a+j-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())

list_y = make_divisors(N)
#  print(list_y)
point = len(list_y)
if point % 2 == 0:
    print(list_y[point // 2] + list_y[point // 2 - 1] - 2)
else:
    point_o = min((list_y[point // 2] + list_y[point // 2 - 1]), (list_y[point // 2] + list_y[point // 2 + 1]))
    print(point_o - 2)

Submission status: Wrong Answer

Solution code:
N = int(input())

min_ = float('inf')
for n in range(1, N // 2 + 1):
    r = N % n

    if r == 0:
        print(n)
        min_ = min(min_, n + N // n - 2)

print(min_)

Submission status: Wrong Answer

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

prime = []

tN = N
for i in range(2, math.ceil(N**0.5)+1):
    while tN%i==0:
        tN //= i
        prime.append(i)
if tN!=1:
    prime.append(tN)

# print(prime)

x=1
y=1
for i,n in enumerate(reversed(prime)):
    if y>x:
        x *= n
    else:
        y *= n

print(x+y-2)

Submission status: Wrong Answer

Solution code:
N=int(input())
p=0
for i in range(1,N):
  if i**2<=N:
    p=p+1
  else:
    break
    
q=p   
for i in range(p,N):
  if N%i!=0:
    q=q+1
  else:
    break
    
print(q+(N//q))

Submission status: Wrong Answer

Solution code:
N = int(input())

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)

# print(fct)

a = 1
for i in range(len(fct) - 1):
    a *= fct[i]

print(a + fct[-1] - 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(math.floor(min(ans)-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


a = prime_factorize(n)
if len(a) == 1:
    print(a[0] - 1)
    exit()
x = 1
y = 1
for i in range(1, len(a)+1):
    if x <= y:
        x *= a[-i]
    else:
        y *= a[-i]
print(x + y - 2)

Submission status: Wrong Answer

Solution code:
import numpy as np
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

N = int(input())
fct = factorize(N)
fct = [1] + fct
ans = np.prod(fct[:-1]) + fct[-1] - 2
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
n = N**0.5

if n % 1 == 0:
  print(2* n -2)
else:
  n = int(round(n, 0))
  while N % n != 0 :
    n = n - 1
  b = N / n
  print(n + b -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.sort()
x = 1
y = 1
i = 0
for pf in pfs:
    if i % 2 == 0:
        x *= pf
    else:
        y *= pf
    i += 1
print(x + y - 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())
divisors = make_divisors(n)
divisors.sort()
res = n
for i in range(int(len(divisors)/2)):
	if res > (divisors[i]+divisors[-(i+1)]-2):
		res = (divisors[i]+divisors[-(i+1)]-2)
print(res)

Submission status: Wrong Answer

Solution code:
from collections  import defaultdict

P=[2]
C=[ 2*i-1 for i in range(2,1000000//2)]
while(1):
    p=C.pop(0)
    P.append(p)
    if p>1000:
        break
    C=[c for c in C if c%p!=0]
P=P+C
#print(len(P))

N=int(input())
#A=defaultdict(int)
A=[]
for p in P:
    while (N%p==0):
        A.append(p)
        N//=p
X=[1,1]
ind=0
for k in sorted( A, reverse=True):
    if (X[0]*k+X[1])>(X[0]+X[1]*k):
        X[1]*=k
    else:
        X[0]*=k
ans= sum(X)-2
if ans==0:
    ans=N-1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
#a ,b  = list(map(int,input().split()))
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
list = prime_factorize(n)
a,b =1,1
for i in range(len(list)):
    if i%2 ==0:
        a *= list[i]
    else:
        b *= list[i]
print(a+b-2)

Submission status: Wrong Answer

Solution code:
def soinsu(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_list = soinsu(int(input()))
result = [1,1]
for s in reversed(soinsu_list):
    if result[0] <= result[1]:
        result[0]*=s
    else:
        result[1]*=s
print(result[0]-1+result[1]-1)

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 i%2 == 0:
        A*=l[i]
    else:
        B*=l[i]

print(A+B-2)

Submission status: Wrong Answer

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

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

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

    return arr

n = int(input())
p = factorizeFlat(n)
a = p.pop(0)
b = p.pop() if len(p) > 0 else 1
while(len(p) > 0):
    #print("a:{} b:{} l:{} r:{} p:{}".format(a, b, p[0], p[-1], p))
    if (a * p[0]) < (b * p[-1]):
        a = a * p.pop(0)
    else:
        b = b * p.pop()
#print("a:{} b:{}".format(a, b))
print(a - 1 + b - 1)

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

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(int(n))
  return table

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

k = make_divisors(n)

ans = Max

for i in range(len(k)//2):
    if ans >= (k[i*2] + k[i*2+1] - 2):
        ans = k[i*2] + k[i*2+1] - 2
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

ans_lis = []
for i in range(1,10**6):
    if N%i==0:
        ans_lis.append(i+(N//i))
print(min(ans_lis)-2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
import sys

N = int(input())

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

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)

while(len(new_ele_l)>2):
    update_ele = new_ele_l[0]*new_ele_l[-1]
    new_ele_l = new_ele_l[1:-1]
    new_ele_l.append(update_ele)
    new_ele_l = sorted(new_ele_l)

print((new_ele_l[0]-1)+(new_ele_l[1]-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())

factor = make_divisors(n)
print((factor[len(factor)//2 - 1] - 1) + (factor[len(factor)//2] - 1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
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
N = int(input())
arr = make_divisors(N)
print(arr[-1]+arr[-2]-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:
            if i != n // i:
                divisors.append(n // i + i)
    divisors.sort()
    return divisors


def main():
    n = int(input())
    divs = make_divisors(n)
    res = divs[0]

    print(res - 2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
li=[]
while N%2==0:
    li.append(2)
    N//=2
waru=3
while waru*waru<=N:
    if N%waru==0:
        li.append(waru)
        N//=waru
    else:
        waru+=2
if N!=1:
    li.append(N)
if len(li)==1:
    print(li[0]-1)
else:
    a=li[0]
    b=li[1]
    for i in range(2,len(li)):
        if a>=b:
            b=b*li[i]
        else:
            a=a*li[i]
    print(a+b-2)

Submission status: Wrong Answer

Solution code:
n = int(input())

m = int(n ** 0.5)

for i in range(1, m)[::-1]:
    if n % i == 0:
        a = n / i
        print(int(i + a -2))
        exit()

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


div = make_divisors(N)
x = div[-2] - 1
y = div[-1] - 1

print(x + y)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
N = int(input())

first_num = 0
second_num = 0
min_diff = N
for i in range(1, int(np.sqrt(N))):
    now_diff = N // i - i
    if N % i == 0 and min_diff > now_diff:
        first_num = i
        second_num = N // i
        min_diff = now_diff
print(first_num + second_num - 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

yakusu = make_divisors(n)
k = (len(yakusu)-1)//2
print(yakusu[k] + yakusu[k+1] -2)

Submission status: Wrong Answer

Solution code:
def sol(n):
    x1 = 1
    while n % 2 == 0:
        x1 *= 2
        n //= 2
        if x1>=n/x1:return x1
    f = 3
    while f * f <= n:
        if n % f == 0:
            x1 *= f
            n //= f
            if x1>=n/x1:return x1
        else:
            f += 2
    return x1

N = int(input())
x1 =  sol(N)
print(x1+N//x1-2)