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:
#
# abc144 c
#
import unittest
from io import StringIO
import sys
import math


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


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

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

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


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

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

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

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


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

Submission status: Wrong Answer

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

a = int(math.sqrt(num))
b = num // a

for i in range(1, a +1):
    b = num // i
    if i * b == num:
        print(i + b - 2)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

min_cnt = N - 1
for i in range(1, int(math.sqrt(N))):
    if N % i == 0:
        j = N // i
        cnt = (i - 1) + (j - 1)
        if min_cnt > cnt:
            min_cnt = cnt
print(min_cnt)

Submission status: Wrong Answer

Solution code:
from math import sqrt

N = int(input())

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

Submission status: Wrong Answer

Solution code:
import math

# 入力
N = int(input())

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

Submission status: Wrong Answer

Solution code:
from math import sqrt

N = int(input())

vals = [1, 1]
tmp = N
idx = 0
for i in range(2, int(sqrt(N)) + 1):
    while tmp % i == 0:
        vals[idx] *= i
        idx = (idx + 1) % 2
        tmp //= i
    if tmp <= 1:break

# print(vals)
if tmp > 1:
    vals[idx] *= tmp
print(sum(vals)-2)

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)


x=1

for i in a[::-1]:
  x *= i
  if x*x >= m:
    break

y = m // x
ans = x + y -2

print(ans)

Submission status: Wrong Answer

Solution code:
import math 
import itertools

num = int(input())

def mk_factor(num):
    factor = 2
    factor_list = []

    while num > 1 and factor < int(math.sqrt(num))+1:
        if num % factor == 0:
            factor_list.append(factor)
            num //= factor
        else:
            factor += 1

    factor_list.append(num)

    return factor_list

def nearest_path(factor_list):
    a = list(itertools.combinations(factor_list, len(factor_list)//2))

    res_list = []

    for item in a:
        temp_list = mk_factor(num)
        factor1 = 1
        factor2 = 1
        for k in item:
            temp_list.remove(k)
            factor2 *= k

        for j in temp_list:
            factor1 *= j
        res_list.append(factor1+factor2)

    return min(res_list) -2

factor_list = mk_factor(num)
print(nearest_path(factor_list))

Submission status: Wrong Answer

Solution code:
import math

def test():
    n = int(input())
    ans = float("inf")
    for i in range(2,int(math.sqrt(n)+1)):
        if n % i == 0:
            ans = min(i+(n//i)-2,ans)
    print(ans)


if __name__ == "__main__":
    test()

Submission status: Wrong Answer

Solution code:
import math

# 入力
N = int(input())

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

Submission status: Wrong Answer

Solution code:
import math

n = int(input())


def solve(n):
    bound = math.floor(math.sqrt(n))
    candidate = n - 1
    for i in range(1, bound):
        q, r = divmod(n, i)
        if r == 0 and i + q - 2 < candidate:
            candidate = i + q - 2

    return candidate


print(solve(n))

Submission status: Wrong Answer

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

for i in range(1,int(n**0.5)+1):
    if n%i==0:
        xlist.append(i)

ans=max(xlist)
print(ans+n/ans-2)

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)


x=1

for i in a[::-1]:
  x *= i
  if x*x > m:
    x //= i
    break

y = m // x
ans = x + y -2

print(ans)

Submission status: Wrong Answer

Solution code:
c=int(input())
count=1
ans=10000000000000
k=c
for i in range(1,int(c**(1/2))):
    if c%i==0:
        count*=i
        k=int(k/i)
        if ans>count+k:
            ans=count+k
print(ans-2)

Submission status: Wrong Answer

Solution code:
from subprocess import*
from collections import*
n=int(input())
p=sorted(map(int,Popen(["factor",str(n)],stdout=PIPE).communicate()[0].decode().split()[1:]))
a=b=1
for c in p:
    if a<b:
        a*=c
    else:
        b*=c
print(a+b-2)

Submission status: Wrong Answer

Solution code:
pf = []
power = []

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

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

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

Submission status: Wrong Answer

Solution code:
from subprocess import*
from collections import*
n=int(input())
p=sorted(map(int,Popen(["factor",str(n)],stdout=PIPE).communicate()[0].decode().split()[1:]))
a=[1,1]
for i,c in enumerate(p):
    a[i%2]*=c
print(sum(a)-2)

Submission status: Wrong Answer

Solution code:

import sys
import heapq
import math

INF = float("inf")

def main():
    N = int(input())
    ans = INF

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
l=[n]
for i in range(int(np.sqrt(n))):
  for j in range(i,int(np.sqrt(n))+1):
    if i*j==n:
      l+=[i+j-2]
print(min(l))

Submission status: Wrong Answer

Solution code:
n = int(input())
l = []
for i in range(1,100001):
    a = n / i
    if a.is_integer():
        l.append(i+n/i)
print(int(min(l)-2))

Submission status: Wrong Answer

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

ans = sys.maxsize
for i in range(2, 10**6+1):
    if n%i == 0:
        ans = min(ans, i+n//i)
print(ans-2)

Submission status: Wrong Answer

Solution code:
import math
import copy
# def is_prime(n,aa):
#     if n == 1: return False
#
#     for k in range(2, int(math.sqrt(n)) + 1):
#         if n % k == 0:
#             return False
#
#     return True
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=int(input())
i=2
j=1
flag=0
x=0
y=0
min=a**0.5
aa=[]
bb=[]
intmin=int(min)
print(intmin)
aa=prime_factorize(a)
atemp=copy.copy(aa)
if a==1:
    print(0)
else:
    for i in range(intmin,a):
        bb=prime_factorize(i)
        for j in range(0,len(bb)):
            if bb[j] in aa:
                aa.remove(bb[j])
            else:
                flag=1
                break

        if flag == 1:
            flag = 0
            aa=copy.copy(atemp)
            # print(aa)
        else:
            if i==a:
                print(a-1)
            else:
                print(i+(a/i)-2)
            break
#     for i in range(2,a//2):
#         mod=a%i
#         if mod==0:
#             if min > (a/i) + i -2:
#                 min = (a/i) + i -2
#     print(min)
# except ZeroDivisionError:
#     print("ZeroDivisionError!!")

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
res = float('inf')
for i in range(1,10**6):
    if (n/i).is_integer():
        res = min(res, i + n/i)
print(int(res-2))

Submission status: Wrong Answer

Solution code:
import math

x = int(input())

tmp = []

for i in range(1, int(math.sqrt(x)) + 1):
    if x % i == 0:
        tmp.append((i - 1) + (x / i - 1))

print(min(tmp))

Submission status: Wrong Answer

Solution code:
N = int(input())

i = 1
result = N

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

print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = N / 2 + 1
i = 1
result = N

while i <= a:
    if N % i == 0:
        result = min(result, N/i + i - 2)
    i = i + 1

print(result)

Submission status: Wrong Answer

Solution code:
import math
import sys

n = int(input())

ans = sys.maxsize

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

print(ans)

Submission status: Wrong Answer

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


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


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

    S = round(math.sqrt(N))
    ans = float('inf')

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


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

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

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

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


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

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = float("inf")

for i in range(1, int(N**0.5)):
    q, m = divmod(N, i)
    if m==0:
        ans = min(ans, q+1)

print(ans-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
 
n = sorted(make_divisors(N))
 
sum_yakusuu = N
for _n in n:
    if _n == 1:
        continue
    if _n+N/_n < sum_yakusuu:
        sum_yakusuu = int(_n+N/_n)
    else:
        if _n == N:
            print(int(_n-1))
        else:
            print(int(_n+N/_n-2))
        break

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
 
n = sorted(make_divisors(N))
 
sum_yakusuu = N
for _n in n:
    if _n == 1:
        continue
    if _n+N/_n < sum_yakusuu:
        sum_yakusuu = int(_n+N/_n)
    else:
        if _n == N:
        	print(int(_n-1))
        else:
            print(int(_n+N/_n-2))
        break

Submission status: Wrong Answer

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


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


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

    S = round(math.sqrt(N))
    ans = float('inf')

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


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

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

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

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


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

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

A = int(math.sqrt(N))

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = N / 2 + 1
i = 2
result = N

while i <= a:
    if N % i == 0:
        result = min(result, N/i + i - 2)
    i = i + 1

print(result)

Submission status: Wrong Answer

Solution code:
import math
import sys

n = int(input())

low = sys.maxsize
a, b = 0, 0
for i in range(1, math.ceil(math.sqrt(n))):
    if n%i == 0 and (i + n//i) <= low:
        a, b = i, n//i
        low = a + b
print(a+b-2)

Submission status: Wrong Answer

Solution code:
n=int(input())
 
def make_divisors(n):
    divisors = []
    for i in range(int(n**0.5)+1, 0, -1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
            return divisors
 
    # divisors.sort()
    return divisors
 
 
k = make_divisors(n)
print(k)
if len(k) == 2:
    print(sum(k)-2)
else:
    print(k.pop()*2-2)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

print(ans-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
 
n = sorted(make_divisors(N))
 
sum_yakusuu = N
for _n in n:
    if _n == 1:
        continue
    if _n+N/_n < sum_yakusuu:
        sum_yakusuu = int(_n+N/_n)
    else:
        if _n == N:
        	print(int(_n+N/_n-1))
        else:
            print(int(_n+N/_n-2))
        break

Submission status: Wrong Answer

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

d=1e12
for i in range(1,int(math.sqrt(n))+1):
    if(n % i == 0):
        m=n/i + i- 2;
        if(m < d):
            d=m
print(d)

Submission status: Wrong Answer

Solution code:
import math
import sys

n = int(input())

low = sys.maxsize
a, b = 0, 0
for i in range(1, math.floor(math.sqrt(n))):
    if n%i == 0 and (i + n//i) <= low:
        a, b = i, n//i
        low = a + b
print(a+b-2)

Submission status: Wrong Answer

Solution code:
data = int(input())
     
ans = float("inf")
flag = True
total = 0
if __name__ == "__main__":
  mdata = data**0.5
  for i in range(2, data):
    for j in range(2, int(mdata)):
        if i * j == data and ans > i+j-2:
          ans = i+j-2
  print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = n
import math
for i in range(int(math.sqrt(n))):
    for j in range(int(math.sqrt(n))):
        if (i+1)*(j+1) == n:
            if i+1 + j+1 < x:
                x = i+1 + j+1
if x == n:
    print(x-1)
else:
    print(x-2)

Submission status: Wrong Answer

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

N = int(input())


def main():
    factorized = factorizer(N)

    A = 1
    B = 1
    for k in factorized:
        while factorized[k] > 0:

            patternA = (A * k) + B
            patternB = A + (B * k)
            patternC = (A * B) + k
            patternmin = min(patternA, patternB, patternC)
            # print("patternA:{0} patternB:{1} patternC:{2} patternmin{3}".format(patternA,patternB,patternC,patternmin))

            if patternmin == patternA:
                A *= k
            elif patternmin == patternB:
                B *= k
            elif patternmin == patternC:
                A = A * B
                B = k

            factorized[k] -= 1
            # print("A,B: {0},{1}".format(A, B))
    print(A + B - 2)


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

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

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

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
tmp = math.ceil(N**(1/2))
ans = N-1
for i in range(3,tmp+1):
    if N%i == 0:
        ans = min(ans,N//i+i)
        ans -= 2

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())

a = 1
b = n

ans = n - 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
import math


def main():
    n = int(input())
    min = n - 1    
    
    for a in range(1, int(math.sqrt(n))):
        b = int(n / a)
        if n==a*b:
            if min > a + b - 2:
                min = a + b - 2
    print(min)
        
        
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math

def solv(N):
    x = N-1
    for i in range(1, int(math.sqrt(N))):
        if N % i == 0:
            x = min(x, i + N / i -2)
    return x

N = int(input())
print(int(solv(N)))

Submission status: Wrong Answer

Solution code:
import math


def main():
    n = int(input())
    min = n - 1    
    
    for a in range(1, int(math.sqrt(n))):
        for b in range(1, a+1):
            if n==a*b:
                if min > a + b - 2:
                    min = a + b - 2
    print(min)
        
        
if __name__ == "__main__":
    main()

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

arr = factorization(N)


A = []
all_seki = 1
for a in arr:
    for i in range(a[1]):
        A.append(a[0])
        all_seki *= a[0]

B = []
B = [[1, all_seki]]
for a in A:
    B.append([a, all_seki//a])

C = []

for b in B:
    C.append(b[0]+b[1]-2)

print(min(C))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
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)
m=len(a)

b=1
c=1
if(m == 1):
    b=a[0]
elif(m == 2):
    b=a[0]
    c=a[1]
elif(m == 3):
    b=a[0]*a[2]
    c=a[1]
elif(m == 4):
    b=a[0]*a[3]
    c=a[1]*a[2]
# elif(m == 5):
#     b=a[0]*a[4]
#     c=a[1]*a[2]*a[3]
# elif(m == 6):
#     b=a[0]*a[5]*a[2](*a[])
#     c=a[1]*a[4]*a[3]
# elif(m == 7):
#     b=a[0]*a[6]*a[2]
#     c=a[1]*a[5]*a[3]*a[4]
elif(m % 4 == 0):
    for i in range(0,int(m/2),2):
        b=b*a[i]*a[m-1-i]
        c=c*a[i+1]*a[m-2-i]
elif(m % 4 == 1):
# 2 2 2 3 5 =120
# 2*5  = 10
# 2*3 * 2 = 12
    for i in range(0,int(m/2)-1,2):
        b=b*a[i]*a[m-1-i]
        # print b
        c=c*a[i+1]*a[m-2-i]
        # print c
    c=c*a[int(m/2)]
elif(m % 4 == 2):
# 2 2 2 2 3 5 =240
# 2*5 * 2 = 20
# 2*3 * 2 = 12
    for i in range(0,int(m/2)-1,2):
        b=b*a[i]*a[m-1-i]
        c=c*a[i+1]*a[m-2-i]
    b=b*a[int(m/2)-1]
    c=c*a[int(m/2)]
elif(m % 4 == 3):
# 2 2 2 2 3 5 5 =1200
# 2*5 * 2 = 20
# 2*3 * 2 * 5 = 60
    # print a
    for i in range(0,int(m/2)-1,2):
        b=b*a[i]*a[m-1-i]
        # print b
        c=c*a[i+1]*a[m-2-i]
        # print c
    b=b*a[int(m/2)-1]
    c=c*a[int(m/2)]*a[int(m/2)+1]
    # print c
print (b+c-2)

Submission status: Wrong Answer

Solution code:
import math

def solv(N):
    x = N-1
    for i in range(1, int(math.sqrt(N))):
        if N % i == 0:
            x = min(x, i + N / i -2)
    return x

N = int(input())
print(solv(N))

Submission status: Wrong Answer

Solution code:
import math

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) #素因数
Y = []
Y.append(1)
c = 1
for j in X:
    c = c*j
    Y.append(c)
#print(Y) #約数:表

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

z = math.sqrt(N)
if z%1 == 0:
    print(int(z)*2 -2)
else:
    print(res-2)

Submission status: Wrong Answer

Solution code:
def allmultiply(N):
	temp = N
	setmulti = []
	mode = -1
	
	while mode != temp:
		#print(mode)
		flag = False
		for i in [2, 3, 5, 7]:
			mode = temp % i
			if mode == 0:
				temp //= i
				flag = True
				setmulti.append(i)
		if flag == False:
			mode = temp
	#if temp != 1:
	setmulti.append(temp)
	setmulti_l = len(setmulti)
	allset = []
	#print(setmulti)

	for i, elem1 in enumerate(setmulti):
		tempset = setmulti[:i]
		if i + 1 < setmulti_l:
			tempset += setmulti[i+1:]
		else:
			pass
		elem2 = 1
		for e in tempset:
			elem2 *= e
		allset.append([elem1, elem2])
	#print(allset)
	mini = 1 << 40
	for e1, e2 in allset:
		tempresult = e1 + e2
		if tempresult < mini:
			mini = tempresult

	return mini- 2

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000)
INF = 1<<48


def solve(N: int):
    def primeFactorize(n: int):
        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 = primeFactorize(N)
    l.append(1)
    l.sort()

    ans = INF

    for i in l:
        M = N // i
        ans = min(ans, M+i-2)

    print(ans)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def input_from_console():
    n = int(input())
    return n


def factor(n):
    factors = []
    tmp = n
    if tmp == 1:
        return [1]
    prime_max = int(n ** (1 / 2.0)) + 1
    i = 2

    while tmp > i:
        if tmp % i == 0:
            factors.append(i)
            tmp = int(tmp / i)
        else:
            i += 1
            if i > prime_max:
                factors.append(tmp)
                return factors
    factors.append(tmp)
    return factors


def multiplyList(myList):
    result = 1
    for x in myList:
        result = result * x
    return result


def solve(n):
    factors = factor(n)
    # print(factors)
    if len(factors) == 1:
        return factors[0] - 1
    else:
        sum_max = multiplyList(factors[0:len(factors)-1]) + multiplyList(factors[len(factors)-1:]) - 2
        # print(multiplyList(factors[0:len(factors)-1]), '*', multiplyList(factors[len(factors)-1:]))
        for i in range(len(factors)):
            sum_tmp = multiplyList(factors[0:i]) + multiplyList(factors[i:]) - 2
            # print(sum_max, sum_tmp)
            if sum_tmp >= sum_max:
                return sum_max
    return 0


def main():
    n = input_from_console()
    print(solve(n))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

print(N-1)

Submission status: Wrong Answer

Solution code:
import sys
import math

n = int(input())

cost = sys.maxsize
tmp = 0
k = math.sqrt(n)
for i in range(1,int(k)):
    q, mod = divmod(n,i)
    if(mod==0):
        tmp = i + int(q) - 2
        cost = min(tmp,cost)
        tmp = 0

print(cost)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N = int(input())
L = round(N**0.5)
kakezan = []
for i in range(1, L+1, 1):
    if N % i == 0:
        a = i
        b = N/i
        c = a+b
        kakezan.append([a, b, c])
kakezan.sort(key=itemgetter(2)) #リスト1は2次元以の配列

A, B, C = kakezan[0]

print(C-2)

Submission status: Wrong Answer

Solution code:
def allmultiply(N):
	temp = N
	setmulti = []
	mode = -1
	
	while mode != temp:
		#print(mode)
		flag = False
		for i in [2, 3, 5, 7]:
			mode = temp % i
			if mode == 0:
				temp //= i
				flag = True
				setmulti.append(i)
		if flag == False:
			mode = temp
	if temp != 1:
		setmulti.append(temp)
	setmulti_l = len(setmulti)
	allset = []
	#print(setmulti)

	for i, elem1 in enumerate(setmulti):
		tempset = setmulti[:i]
		if i + 1 < setmulti_l:
			tempset += setmulti[i+1:]
		else:
			pass
		elem2 = 1
		for e in tempset:
			elem2 *= e
		allset.append([elem1, elem2])
	#print(allset)
	mini = 1 << 40
	for e1, e2 in allset:
		tempresult = e1 + e2
		if tempresult < mini:
			mini = tempresult

	return mini- 2

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

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

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

res = 100000000000
for i, x in tmp:
    Min =  (i-1) + (x-1)
    if res > Min:
        res = Min

print(res)

Submission status: Wrong Answer

Solution code:
import math

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

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

Submission status: Wrong Answer

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


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


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

    S = round(math.sqrt(N))

    for i in range(S):
        for j in range(i, S):
            if i*j == N:
                print(i+j-2)


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

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

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

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


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