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 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
k=int(input())
l=factorization(k)
tmp=float("inf")
kk=k
for i in range(len(l)):
    a,b=l[i][0],l[i][1]
    for j in range(b):
        kk/=a
        s=k/kk
        tt=s+kk
        if tmp>tt:
            tmp=tt
    kk=k
print(int(tmp-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
k=int(input())
l=factorization(k)
tmp=float("inf")
for i in range(len(l)):
    kk=k
    a,b=l[i][0],l[i][1]
    for j in range(b):
        kk/=a
        s=k/kk
        tt=s+kk
        if tmp>tt:
            tmp=tt
print(int(tmp-2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = []
for i in range(1,10**6):
    if N%i == 0:
        j = N//i
        ans.append(i+j-2)
    else:
        continue

print(min(ans))

Submission status: Wrong Answer

Solution code:
import itertools
N = int(input())
   
ans = []
for i in range(1,10**6):
    if N%i == 0:
        j = N//i
        ans.append(i-1+j-1)
    else:
        continue

print(min(ans))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
n = int(math.floor(math.sqrt(N)))

ans = N - 1
for i in range(1,n):
  if N % i != 0:
    pass
  else:
    ans = min((i + N//i - 2), ans)
    
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import numpy as np

n = int(input())
n_2 = int(math.sqrt(n + 1))
x = np.arange(1, n_2)
div = x[n % x == 0]
ans = 10 ** 12
for i in div:
    j = (n // i) + i - 2
    ans = min(ans, j)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import numpy as np

# nのルートに最も近い整数のペアが答え
# nをnのルートまで試し割すればよい
n = int(input())
n_2 = int(math.sqrt(n + 100))   # 試し割りする数の最大値をnの平方根とした整数のリスト　少し足らないことがあるといけないので、100足した
x = np.arange(1, n_2)
div = x[n % x == 0]
ans = 10 ** 12
for i in div:
    j = n // i + i - 2
    ans = min(ans, j)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import permutations

N = int(input())
i, j = 1, 1
max0 = -1
ans = 0
while i < N // i:
    if N % i != 0:
        i += 1
        continue
    else:
        j = N // i
        if max0 > abs(i-j) or max0 == -1:
            max0 = abs(i-j)
            ans = i + j
        i += 1
print(ans-2)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import permutations

N = int(input())
val = []
i = 2

while i * i <= N:
    while N % i == 0:
        N //= i
        val.append(i)
    i += 1
if N > 1:
    val.append(N)

a, b = 1, 1
for i in val[0::2]:
    a *= i
for i in val[1::2]:
    b *= i

a, b = 0, 0
max0 = 0
for i in permutations(val):
    max1 = 1
    max2 = 1
    for j in i[0::2]:
        max1 *= j
    for j in i[1::2]:
        max2 *= j
    if max0 == 0 or abs(max1 - max2) < max0:
        max0 = abs(max1 - max2)
        a = max1
        b = max2
    
print(a + b - 2)

Submission status: Wrong Answer

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

val = []
i = 2
while i * i <= N:
    while N % i == 0:
        N //= i
        val.append(i)
    i += 1
if N > 1:
    val.append(N)

a, b = 1, 1
for i in val[0::2]:
    a *= i
for i in val[1::2]:
    b *= i

print(a + b - 2)

Submission status: Wrong Answer

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

import math
N = int(readline())

ans = N

for i in range(1, math.ceil(math.sqrt(N))):
    if N % i == 0:

        if i == 1:
            ans = min(ans, i + N//i - 1)
        else:
            ans = min(ans, i + N//i - 2)


print(ans)

Submission status: Wrong Answer

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

import math
N = int(readline())

ans = N

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


print(ans)

Submission status: Wrong Answer

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

import math
N = int(readline())

diff = N
pair = [0, 0]

for i in range(1, math.ceil(math.sqrt(N))):
    if N % i == 0:
        j = N // i

        if abs(i-j) <= diff:
            diff = i + abs(i-j)
            pair = [i-1, j-1]

print(sum(pair))

Submission status: Wrong Answer

Solution code:
n=int(input())
res1=0
res2=0
ans=float("INF")
for i in range(1,n+1):
    if n%i==0:
        res1=i
        res2=n/i
        ans=min(ans,res1+res2)
        break
print(int(ans-2))

Submission status: Wrong Answer

Solution code:
N = int(input())

def factorize(n):
   from collections import defaultdict
   factor = defaultdict(int)
   orig = n
   i = 2
   while orig // i > i:
      if n % i == 0:
         factor[i] += 1
         n //= i
      else:
         i += 1
   else:
      factor[n] += 1
   return factor

factor = factorize(N)

a, b = 1, 1
for num, count in reversed(sorted(factor.items(), key=lambda x: x[0])):
   for i in range(count):
      if a < b:
         a *= num
      else:
         b *= num
print(a + b - 2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np

def factorization(n):
    res = []
    x = n
    y = 2
    while y*y <= x:
        while x % y == 0:
            res.append(y)
            x //= y
        y += 1
    if x > 1:
        res.append(x)

    return res

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

    ns = factorization(N)

    ans = 10**12 + 1
    for i in range(1, len(ns)+1):
        for j in itertools.combinations(ns, i):
            val1 = np.prod(j)
            if val1 > N/2:
                break
            val2 = N // val1
            ans = min(ans, val1+val2-2)

    print(ans)

solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
res = []
x = n
y = 2
while y*y <= x:
    while x % y == 0:
        res.append(y)
        x //= y
    y += 1
if x > 1:
    res.append(x)

res.sort(reverse=True)
a = 1
b = 1
while res:
    
    if a < b:
        a *= res.pop()
    else:
        b *= res.pop()
print(a-1+b-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
res = []
x = n
y = 2
while y*y <= x:
    while x % y == 0:
        res.append(y)
        x //= y
    y += 1
if x > 1:
    res.append(x)

res.sort()
a = 1
b = 1
while res:
    
    if a < b:
        a *= res.pop()
    else:
        b *= res.pop()
print(a-1+b-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
res = []
x = n
y = 2
while y*y <= x:
    while x % y == 0:
        res.append(y)
        x //= y
    y += 1
if x > 1:
    res.append(x)

res.sort()
a = 1
b = 1
c = 0
while res:
    if c % 2 == 0:
        a *= res.pop()
    else:
        b *= res.pop()
    c+=1
print(a-1+b-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
res = []
x = n
y = 2
while y*y <= x:
    while x % y == 0:
        res.append(y)
        x //= y
    y += 1
if x > 1:
    res.append(x)

a = 1
b = 1
c = 0
while res:
    if c % 2 == 0:
        a *= res.pop()
    else:
        b *= res.pop()
    c+=1
print(a-1+b-1)

Submission status: Wrong Answer

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

# 素数がどうか判定
flag = 0
for i in range(2, int(math.sqrt(N)), 1):
  if N % i == 0:
    flag = 1
    break
if flag == 0:
  print(N-1)
else:
  res = 0
  idx = int(math.sqrt(N))
  for i in range(idx, 0, -1):
    if N % i == 0:
      res = i + int(N/i) - 2
      print(res)
      break

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = []
i = 2
a = int()
b = int()
ans = 10**12+1
for i in range(2,int(np.sqrt(N))):
    if N%i ==0:
        A.append(i)

if len(A) == 0:
    print(N-1)
else:
    for j in range(len(A)):
        a = A[j]-1
        b = (N/A[j])-1
        if a+b <= ans:
            ans = a+b
    print(int(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

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

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

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

    return factorization_list

if __name__ == "__main__":
        
    N = int(input())
    factor_array = np.array(factorization(N))
    distance = 10**12

    for v in range(len(factor_array)):
        i = np.prod(factor_array[:v+1])
        j = np.prod(factor_array[v+1:])
        if i < 0 or j < 0:
            continue
        distance = min(distance, i+j-1-1)

    print(distance)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

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

    return factorization_list

if __name__ == "__main__":
        
    N = int(input())
    factor_array = np.array(factorization(N))
    distance = 10**12
    
    for v in range(len(factor_array)):
        i = np.prod(factor_array[:v+1])
        j = np.prod(factor_array[v + 1:])
        distance = min(distance, i+j-1-1)

    print(distance)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

def main():
    N = int(input())
    ans = float('inf')
    for i in range(2, 10 ** 6 + 1):
        if N % i == 0:
            tmp = (i-1) + (N // i -1)
            ans = min(ans, tmp)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

N = int(input())
l = make_divisors(N)

ans = float("inf")
for i in range(len(l)//2):
    ans = min(ans, l[i]-1+N//l[i]-1)
print(ans)

Submission status: Wrong Answer

Solution code:
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

N = int(input())
l = make_divisors(N)

ans = float("inf")
for i in range(len(l)//2):
    ans = l[i]-1+N//l[i]-1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

factors = []
i = 2
num = N
while i*i <= num:
  if num%i==0:
    while num%i==0:
      factors.append(i)
      num //= i
  i += 1
if num != 1:
  factors.append(num)

if len(factors) == 1:
  print(N-1)
  exit()

x,y = 1,1
l,r = 0, len(factors)-1
while l < r:
  x *= factors[l]
  y *= factors[r]
  l += 1
  r -= 1
if len(factors)%2==1:
  x *= factors[l]

print(x-1+y-1)

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


def main():
    n = int(input())
    divs = sorted(divisor(n))
    left = len(divs)//2 - 1
    right = len(divs)//2
    ans = divs[left] + divs[right] - 2
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.buffer.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

m = float('inf')
n = ri()
for i in range(1, int(n**0.5) + 1, 2):
  a = n//i
  if a*i == n:
    if m > a+i:
      m = a+i
else:
  print(m-2)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.buffer.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

m = float('inf')
n = ri()
for i in range(1, int(n**0.5), 2):
  a = n//i
  if a*i == n:
    if m > a+i:
      m = a+i
else:
  print(m-2)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.buffer.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

inf = float('inf')

m = inf
n = ri()
for i in range(1, n//2):
  a = n//i
  if a*i == n:
    if m > a+i:
      m = a+i
else:
  print(m-2)

Submission status: Wrong Answer

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

# 約数列挙
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

n = int(readline())

l = make_divisors(n)
if len(l) % 2 == 0:
    ans = l[len(l) // 2 - 1] - 1 + l[len(l) // 2] - 1
else:
    ans = l[(len(l) + 1) // 2 - 1] - 1 + l[(len(l) + 1) // 2] - 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
m=int(input())

pf={}
for i in range(2,int(m**0.5)+1):
    while m%i==0:
        pf[i]=pf.get(i,0)+1
        m//=i
if m>1:pf[m]=1

a=1
b=1
pf=sorted(pf.items(), reverse=True)
#print(pf)
for k,v in pf:
    for i in range(v):
        if a<=b:
            a*=k
        else:
            b*=k
print(a+b-2)

Submission status: Wrong Answer

Solution code:
m=int(input())

pf={}
for i in range(2,int(m**0.5)+1):
    while m%i==0:
        pf[i]=pf.get(i,0)+1
        m//=i
if m>1:pf[m]=1

a=1
b=1

for k,v in pf.items():
    for i in range(v):
        if a<=b:
            a*=k
        else:
            b*=k
print(a+b-2)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a = [1,1]
ans = 100000000000000
for i in range(int(math.sqrt(n))):
    a[0] += 1
    if(n%a[0] == 0):
        ans =min(ans,a[0] + int(n/a[0])-2)
    

a[1] = int(n/a[0])

print(ans)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a = [1,1]
ans = 100000000000
for i in range(int(math.sqrt(n))):
    a[0] += 1
    if(n%a[0] == 0):
        ans =min(ans,a[0] + int(n/a[0])-2)
    

a[1] = int(n/a[0])

print(ans)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a = [1,1]
ans = 100000000
for i in range(int(math.sqrt(n))):
    a[0] += 1
    if(n%a[0] == 0):
        ans =min(ans,a[0] + int(n/a[0])-2)
    

a[1] = int(n/a[0])

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [1,1]
ans = 100000000
for i in range(1000000):
    a[0] += 1
    if(n%a[0] == 0):
        ans =min(ans,a[0] + int(n/a[0])-2)
    
    if( i >=n):
        break


print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
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)
a.sort(reverse = True)

b=[1,1]

for i in range(len(a)):
    if(b[0] == b[1]):
        b[0] = b[0] * a[i]
    else:
        if(b[0] > b[1]):
            b[1] = b[1] * a[i]
        else:
            b[0] = b[0] * a[i]
 

ans = b[0] + b[1] -2
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
ans = float('inf')
for i in range(1,math.ceil(math.sqrt(N))):
    if N % i == 0:
        j = N//i
        if ans > i+j-2:
            ans = i+j-2
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

a = prime_factorize(N)
if len(a) == 1:
    print(N-1)
else:
    minAns = float('inf')
    for i in range(0, len(a)):
        x = 1
        y = 1
        for j in a[0:i:]:
            x *= j
        for k in a[i::]:
            y *= k
        if x-1 + y-1 < minAns:
            minAns = x-1 + y-1
    print(minAns)

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)
print(a)
if len(a) == 1:
    print(N-1)
else:
    minAns = float('inf')
    for i in range(0, len(a)):
        x = 1
        y = 1
        for j in a[0:i:]:
            x *= j
        for k in a[i::]:
            y *= k
        if x-1 + y-1 < minAns:
            minAns = x-1 + y-1
    print(minAns)

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(N-1)
else:
    minAns = 10**13
    for i in range(0, len(a)):
        x = 1
        y = 1
        for j in a[0:i:]:
            x *= j
        for k in a[i::]:
            y *= k
        if x-1 + y-1 < minAns:
            minAns = x-1 + y-1
    print(minAns)

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(N-1)
else:
    minAns = 10**13
    for i in range(1, len(a)):
        x = 1
        y = 1
        for j in a[0:i:]:
            x *= j
        for k in a[i::]:
            y *= k
        if x-1 + y-1 < minAns:
            minAns = x-1 + y-1
    print(minAns)

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)
while len(a) > 2:
    n = a.pop()
    a[0] = a[0]*n

if len(a) == 1:
    print(N-1)
else:
    print(a[0]-1 + a[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())
lst = make_divisors(N)
lst.sort()
for i in range(N):
    if lst[i]*lst[i+1] >= N:
        break
print(lst[i+1]-1+lst[i]-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())
lst = make_divisors(N)
lst.sort()
for i in range(N):
    if lst[i]*lst[i+1] >= N:
        break
print(lst[i+1]-lst[i])

Submission status: Wrong Answer

Solution code:
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 = prime_factorize(N)
A.append(1)

while len(A) > 2:
    A[0] = A[0] * A[1]
    del A[1]
    A.sort()
print(A[0]+A[1]-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


l = make_divisors(n)
x = l[len(l) // 2] + l[len(l) // 2 - 1] - 2

print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())

n = N ** (1/2)

ans = N
for i in range(1, int(n)):
  if N % i == 0:
    ans = min(i + N//i - 2, ans)
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)

    return divisors

def walk_on_multiplication_table(n):

    ans = 10**13
    yaku = make_divisors(n)
    yaku.sort()
    count = len(yaku)
    for i in range(int(count//2)):
        ans = min(ans, (yaku[i]+yaku[count-i-1]-2))

    if count % 2 == 0:
        return ans
    print((yaku[int(count//2)]*2)-2)
    return min(ans, (yaku[int(count//2)]*2)-2)

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

if __name__ == '__main__':
    main()

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

def walk_on_multiplication_table(n):

    ans = 10**13
    yaku = make_divisors(n)
    yaku.sort()
    count = len(yaku)
    for i in range(int(count//2)):
        ans = min(ans, (yaku[i]+yaku[count-i-1]-2))

    if count % 2 == 0:
        return ans

    return min(ans, (yaku[int((count//2))]**2-2))

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

if __name__ == '__main__':
    main()

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

def walk_on_multiplication_table(n):

    ans = 10**13
    yaku = make_divisors(n)
    yaku.sort()
    count = len(yaku)
    for i in range(int(count//2)):
        ans = min(ans, (yaku[i]+yaku[count-i-1]-2))

    if count % 2 == 0:
        return ans

    return min(ans, (yaku[int((count//2)+1)]**2-2))

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
min_num = N+2

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

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
min_num = N
flg = False
for i in range(2,int(math.sqrt(N))):
    if N % i == 0:
        flg = True
        if (i + (N // i)) < min_num:
            min_num = (i + (N // i))
if flg:
    print(min_num - 2)
else:
    print(min_num - 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = 0
    N = int(input())
    y = []
    for i in range(1, int(N**0.5)+1):
        if N%i == 0:
            y.append(i)
            if i != N // i:
                y.append(N//i)
    ans += y[-1]-1 + y[-2]-1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a= []
def div(n):
    if(n==0):
        return
    if(n==1):
        a.append(1)
        return
    while(n%2==0):
        n //= 2
        a.append(2)

    f = 3
    while(f*f <= n):
        if(n%f==0):
            n //= f
            a.append(f)
        else:
            f += 2

    if(n!=1):
        a.append(n)

div(n)
l = len(a)

xs = 1
ys = 1
for i in range(l):
    if(xs <= ys):
        xs *= a[i]
    else:
        ys *= a[i]

print(xs+ys-2)

Submission status: Wrong Answer

Solution code:
n = int(input())
a= []
def div(n):
    if(n==0):
        return
    if(n==1):
        a.append(1)
        return
    while(n%2==0):
        n //= 2
        a.append(2)

    f = 3
    while(f*f <= n):
        if(n%f==0):
            n //= f
            a.append(f)
        else:
            f += 2

    if(n!=1):
        a.append(n)

div(n)
l = len(a)
x = []
y = []
for i in range(l//2):
    x.append(a[i])
    y.append(a[l-1-i])
if(l%2!=0):
    x.append(a[l//2])

xs = 1
ys = 1
for i in x:
    xs *= i
for i in y:
    ys *= i
print(xs+ys-2)

Submission status: Wrong Answer

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

ans=10**12
for i in range(1, int(math.sqrt(n))):
    if n%i==0:
        tmp=i+n/i-2
        if tmp < ans:
            ans=tmp
    else:
        continue

print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 10**12

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

Submission status: Wrong Answer

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

for k in range(1,int((n+1)**0.5)):
    if n%k == 0 :
        m = n//k + k - 2
        if ans > m:
            ans = m
        else:
            print(ans)
            sys.exit()
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 10**12

for k in range(1,n+1//2):
    if n%k == 0 :
        m = n//k + k - 2
        if ans > m:
            ans = m

print(m)

Submission status: Wrong Answer

Solution code:
def solution(N):
    p, q = N, 1
    min_sum = p + q

    for i in range(2, int(N ** 0.5)):
        m, r = divmod(N, i)

        if r == 0 and m + i < min_sum:
            min_sum = m + i
            p, q = m, i

    return p + q - 2



if __name__ == '__main__':
    N = int(input())
    a = solution(N)
    print(a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=n
for i in range(2,n):
  if n%i:continue
  j=n//i
  if j<i:break
  ans=j+i-2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
tmp = 1
 
for i in range(1,10**10):
  if n%i == 0:
    if i <= n//i:
      tmp  = i
    else:
      break
  elif tmp == 1 and i >= n/i:
    break

Submission status: Wrong Answer

Solution code:
n = int(input())
tmp = 1
 
for i in range(1,10**10):
  if n//i == 0:
    if i <= n//i:
      tmp  = i
    else:
      break
  elif tmp == 1 and i >= n/i:
    break
    
      
print(tmp + (n//tmp) -2)

Submission status: Wrong Answer

Solution code:
n = int(input())
tmp = 1

for i in range(1,10**10):
  if n//i == 0:
    if i <= n//i:
      tmp  = i
    else:
      break
      
print(tmp + (n//tmp) -2)