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:
n = int(input())

def divisor(n: int) -> list:
    list_of_divisor = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            list_of_divisor.append(i)
            if i != n//i:
                list_of_divisor.append(n//i)
    list_of_divisor.sort()
    return list_of_divisor

li = divisor(n)
num = len(li)
if num % 2 == 0:
    # print(li[num//2-1], li[num//2])
    if li[num//2-1] == 1:
        print(li[num//2]-1)
    else:
        print((li[num//2-1]-1)+(li[num//2]-1))
else:
    print(li[num//2]**2)

Submission status: Wrong Answer

Solution code:
N = int(input())
N = N // 2
ans = N -1

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

print(ans)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

def factors(n):    
    return set(reduce(list.__add__, 
                ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

def prime(n1):
	for i in range(2, int(math.sqrt(n1))):
		if n1%i == 0:
			return False
	return True

n = int(input())
if prime(n):
	print(n - 1)
else:
	k = sorted(list(factors(n)))
	#print(k)
	s = k[len(k)//2 - 1] + k[len(k)//2]
	print(s - 2)

Submission status: Wrong Answer

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


def main():
    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)
    if len(l)%2 == 0:
        choices = [l[len(l)//2-1], l[len(l)//2]]
        print(choices[0] + choices[1] - 2)
    else:
        print(l[len(l)//2 + 1] * 2 -2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

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]))
  
print(ans-2)

Submission status: Wrong Answer

Solution code:
n = int(input())
mx = int(1000)
y=0
mn = int(10e13)
for v in range(1,mx):
    if v<=n and n%v==0:
        y=1
        left = n//v
        mn=min(v-1+left-1,mn)
    if v>n:
        break
if y:
    print(mn)
else:
    print(n-1)

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 = 10**12+4
if n == 2:
    print(0)
else:
    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:
n = int(input())
factor = []
tmp = n
for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
    while tmp % i == 0:
        factor.append(i)
        tmp //= i
if tmp != 1:
    factor.append(tmp)
if len(factor) == 0:
    factor.append(n)
if len(factor) == 1:
    print(factor[0] - 1)
else:
    a, b = 1, 1
    for i in sorted(factor, reverse=True):
        if a < b:
            a *= i
        else:
            b *= i
    print(a + b - 2)

Submission status: Wrong Answer

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

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

    divs = trial_division(N)
    d = len(divs)
    ans = float('inf')
    for i in range(d):
        for j in range(i+1, d):
            if divs[i] * divs[j] == N:
                ans = min(ans, divs[i] - 1 + divs[j] - 1)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

for i in reversed(range(1,math.ceil(math.sqrt(N)))):
    if N % i == 0:
        a = i
        b = N / i
        break

print(int(a + b - 2))

Submission status: Wrong Answer

Solution code:
n=int(input())
import math
list=[ ]
for i in range(1,math.floor(n*0.5)+2):
  if float(n/i).is_integer()==True:
    j=n/i
    list.append(i+j)
print(list)
print(min(list)-2)

Submission status: Wrong Answer

Solution code:
N = int(input())
Alist = []
Blist = []
flag = 0

for i in range(1,10**6):
    if N%i==0:
        Alist.append(int(i)+int(N//i)-2)
        flag = 1

if flag ==0:
    Alist.append(N-1)

print(min(Alist))

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)
tmp = []
if len(div)%2 == 0:
    tmp.append(div[int(len(div)/2)])
    tmp.append(div[int(len(div)/2-1)])
ans = 0
ans = sum(tmp)-2
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

import numpy as np

def main():
    n = int(input())
    tmp = prime_factorize(n)
    
    ans = 100000000000000
    for i in range(len(tmp)):
        ans_tmp = np.prod(tmp[0:(i+1)]) + np.prod(tmp[(i+1)::])
        if ans > ans_tmp:
            ans = ans_tmp
            
    ans -= 2
    print(ans)




if __name__ == '__main__':
    main()

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(len(a)):
    if x <= y:
        x *= a[-i]
    else:
        y *= a[-i]
print(x + y - 2)

Submission status: Wrong Answer

Solution code:
# https://qiita.com/snow67675476/items/e87ddb9285e27ea555f8
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())
pfs = factorization(n)



pf = []
for lis in pfs:
    pf.extend([lis[0] for _ in range(lis[1])])

a = 1
b = 1
for i in range(len(pf)):
    if i % 2 == 0:
        a *= pf[i]
    else:
        b *= pf[i]
print(a - 1 + b - 1)

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest


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


def resolve():
    N = int(input())
    A = 1
    A_count = 0
    B = 1
    B_count = 0
    facts = factorization(N)
    for fact in facts:
        val = fact[0]
        num = fact[1]
        for i in range(num):
            if A_count > B_count:
                B *= val
                B_count += 1
            else:
                A *= val
                A_count += 1
    result = A - 1 + B - 1
    print(result)


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

Submission status: Wrong Answer

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

mean = int(np.sqrt(n))

for i in range(mean):
    div = mean - i
    if n % div == 0:
        print(div + n/div - 2)
        break

Submission status: Wrong Answer

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

n = int(input())

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

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

def factors(n):    
    return set(reduce(list.__add__, 
                ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

def prime(n1):
	for i in range(2, int(math.sqrt(n1))):
		if n1%i == 0:
			return False
	return True

n = int(input())
if prime(n):
	print(n - 1)
else:
	k = sorted(list(factors(n)))
	#print(k)
	s = k[len(k)//2] + k[len(k)//2 + 1]
	print(s - 2)

Submission status: Wrong Answer

Solution code:
N = int(input())
N = N // 2
ans = N -1

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

print(ans)

Submission status: Wrong Answer

Solution code:
def trial_division(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())
T = trial_division(N)

D = {}
for t in T :
    if t not in D :
        D[t] = 1
    else :
        D[t] += 1

U = []
for t in D :
    for i in range(D[t]+1) :
        U.append(t**i)

S = set(U)
ans = N-1
for s in S :
    a = N//s
    ans = min(ans,s+a-2)
print(ans)

Submission status: Wrong Answer

Solution code:
def isprime(x):
    if x==1:
        return False
    for i in range(2,int(x**0.5)+1):
        if x % i == 0:
            return False
    else:
        return True

def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

n = int(input())
if n==1:
    print(0)
elif isprime(n):
    print(n-1)
else:
    lst = factorize(n)
    lst.sort(reverse = True)
        
    num = [1,1]
    for i in range(len(lst)):
        if num[0] <= num[1]:
            num[0] *= lst[i]
        else:
            num[1] *= lst[i]
    print(num[0] + num[1] - 2)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from itertools import accumulate
from operator import mul
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

def accum(s):
    value = 1
    for ss in s:
        value = value*ss
    return value

def solve(N: int):
    soinsuu = [1]+prime_decomposition(N)
    answer = 10**12
    
    for i in range(1,len(soinsuu)):
        distance = accum(soinsuu[:i])+accum(soinsuu[i:])
        answer = min(answer,distance)

    print(int(answer)-2)
    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:
import math
import sys

N = int(input())

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

Submission status: Wrong Answer

Solution code:
n = int(input())

def divisor(n: int) -> list:
    list_of_divisor = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            list_of_divisor.append(i)
            if i != n//i:
                list_of_divisor.append(n//i)
    list_of_divisor.sort()
    return list_of_divisor

li = divisor(n)
num = len(li)
if num % 2 == 0:
    # print(li[num//2-1], li[num//2])
    if li[num//2-1] == 1:
        print(li[num//2]-1)
    else:
        print((li[num//2-1]-1)*(li[num//2]-1))
else:
    print(li[num//2]**2)

Submission status: Wrong Answer

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

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

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

    return arr

n = int(input())

a = 1
b = 1

fct = factorization(n)

for x, y in reversed(fct):
    for _ in range(y):
        if a <= b:
            a *= x
        else:
            b *= x

print(a+b-2)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
r = int(math.sqrt(n))

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

Submission status: Wrong Answer

Solution code:
N=int(input())
for j in range(1,10):
    for i in range(1,10):
        if N==i*j:
            print("Yes")
            exit()
print("No")

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(len(a)):
    if i % 2 == 0:
        x *= a[-i]
    else:
        y *= a[-i]
print(x + y - 2)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = np.array(int(input()))

a = 1
b = n

for i in reversed(range(2, int(round(np.sqrt(n))))):
    if n % i ==  0:
        a = int(i)
        b = int(n / i)
        break
    else:
        continue

print(int(a + b - 2))

"""
10
5

50
13

10000000019
10000000018

"""

Submission status: Wrong Answer

Solution code:
n=int(input())
l=1
for i in range(1,int(n**0.5)):
	if n%i==0:
		l=i
k=n//l
print(l+k-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())

n = make_divisors(N)
n.sort()
mannaka_ = int(len(n)/2)
mannaka = mannaka_ - 1
print((n[mannaka_]-1)+ (n[mannaka]-1))

Submission status: Wrong Answer

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

a=0
b=0
for i in range(int(math.sqrt(n)),1,-1):
  if n%i==0:
    a=i
    b=n//i
if a==0:
  print(n-1)
else:
  print(a+b-2)

Submission status: Wrong Answer

Solution code:
a=int(input(""))


b=a/2
c=a/3
d=a/4
e=a/5
f=a/6
g=a/7
h=a/8
i=a/9

if b==1 or b==2 or b==3 or b==4 or b==5 or b==6 or b==7 or b==8 or b==9:
    print("yes")
if c==1 or c==2 or c==3 or c==4 or c==5 or c==6 or c==7 or c==8 or c==9:
    print("yes")
if d==1 or d==2 or d==3 or d==4 or d==5 or d==6 or d==7 or d==8 or d==9:
    print("yes")
if e==1 or e==2 or e==3 or e==4 or e==5 or e==6 or e==7 or e==8 or e==9:
    print("yes")
if f==1 or f==2 or f==3 or f==4 or f==5 or f==6 or f==7 or f==8 or f==9:
    print("yes")
if g==1 or g==2 or g==3 or g==4 or g==5 or g==6 or g==7 or g==8 or g==9:
    print("yes")
if h==1 or h==2 or h==3 or h==4 or h==5 or h==6 or h==7 or h==8 or h==9:
    print("yes")
if i==1 or i==2 or i==3 or i==4 or i==5 or i==6 or i==7 or i==8 or i==9:
    print("yes")

Submission status: Wrong Answer

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

list=[]
list=make_divisors(a)
print(list[int(len(list)/2)]-1+list[int(len(list)/2)-1]-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
#a,b = map(int,input().split())
#li = list(map(int,input().split()))
a = int(n**0.5//1)

for i in range(1,a+n):
    if n%(a+i) ==0 :
        #print(a,i)
        print(n//(a+i)-1+(a+i-1))
        exit()

Submission status: Wrong Answer

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

n = int(input())

f = factorize(n)
s = 1
if len(f) > 2:
    for i in range(len(f)-1):
        s *= f[i]    

    if s == 1 or f[-1] == 1:
        print(s+f[-1]-1)
    else:
        print(s+f[-1]-2)
elif len(f) == 1:
    print(f[0]-1)
else:
    if f[0] == 1 or f[-1] == 1:
        print(f[0]+f[-1]-1)
    else:
        print(f[0]+f[-1]-2)

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()
div = divisor(N)
#print(div, div[len(div)//2 - 1])

i = div[len(div)//2 - 1] - 1
j = N // div[len(div)//2 - 1]  - 1
ans = i + j

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
def factorize(n):
    b = 2
    fct = []
    fct.append(1)
    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())
listN = factorize(N)
x = 0
y = 0
mini = 10**12
if len(listN) == 1:
    x = N
    y = 1
else:
    for i in range(len(listN)):
        for j in range(i+1,len(listN)):
            x0 = listN[i]*listN[j]
            y0 = N//x0
            if mini > abs(x0-y0):
                mini = abs(x0-y0)
                x = x0
                y = y0

print(x-1+y-1)

Submission status: Wrong Answer

Solution code:
import collections

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

import numpy as np

def main():
    n = int(input())
    print(prime_factorize(n))
    tmp = prime_factorize(n)
    
    ans = 100000000000000
    for i in range(len(tmp)):
        ans_tmp = np.prod(tmp[0:(i+1)]) + np.prod(tmp[(i+1)::])
        if ans > ans_tmp:
            ans = ans_tmp
            
    ans -= 2
    print(ans)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


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

    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)

    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:
n = int(input())

if n == 1:
    print(0)
    exit()

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)

if len(res) == 1:
    print(sum(res) - 1)
    exit()

while len(res) != 2:
    res.sort(reverse=True)
    res.append(res.pop(-1) * res.pop(-1))
print(sum(res) - 2)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
root = math.floor(n**(1/2))
for i in reversed(range(1,root)):
         if n % i == 0:
                  print((i-1)+((n//i)-1))
                  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

a = make_divisors(N)
print(a[len(a)//2-1]-1 +  a[len(a)//2]-1)

Submission status: Wrong Answer

Solution code:
import math

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

    return arr


N = int(input())
ll = factorization(N)

x = 1
y = 1
ll.sort(key=lambda x: x[0], reverse=True)
for l in ll:
    for _ in range(l[1]):
        if x < y:
            x *= l[0]
        else:
            y *= l[0]

# print(f'{x},{y}')

print((x-1)+(y-1))

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 = 10**12+4
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:
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct


if __name__ == "__main__":
    N = int(input())

    div = factorize(N)

    A, B = 1, 1

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

    print(A+B-2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

factor_a = 0
factor_b = 0

if n % 2 == 1:
	odd_root = int(n ** 0.5)
	while odd_root % 6 != 0:
		odd_root += 1
	for i in range(odd_root, n+6, 6):
		if n % (i-1) == 0:
			factor_a = i-1
			factor_b = n / (i-1)
			break
		elif n % (i+1) == 0:
			factor_a = i-1
			factor_b = n / (i-1)
			break
else:
	for i in range(int(n ** 0.5), n+1):
		if n % i == 0:
			factor_a = i
			factor_b = n / i
			break

print(int(factor_a - 1 + factor_b - 1))

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)
if len(a) == 2:
    c,d=a[0],a[1]
else:
    c,d = 1,1
    for i in range(0,len(a),2):
        c*=a[i]
    for j in range(1,len(a),2):
        d*=a[j]
print(c+d-2)

Submission status: Wrong Answer

Solution code:
def trial_division(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())
T = trial_division(N)

D = {}
for t in T :
    if t not in D :
        D[t] = 1
    else :
        D[t] += 1

U = []
for t in D :
    for i in range(D[t]+1) :
        U.append(t**i)



if len(T) == 1 :
    ans = N-1
else :
    ans = float("inf")
    for u in U :
        t = N//u
        ans = min(ans, t+u-2)
print(ans)

Submission status: Wrong Answer

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

    #divisors.sort()
    return divisors

n = int(input())
lis = make_divisors(n)
print(lis[-1]+lis[-2]-2)

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())
List = prime_factorize(N)
List.reverse()

A=1
B=1

for i in List:
    if(A<=B):
        A=A*i
    else:
        B=B*i
print(A+B-2)

Submission status: Wrong Answer

Solution code:

N = int(input())

#nの素因数分解を行いリストを返す
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

li = prime_factorize(N)

#Nが素数
if len(li) == 1:
    print(N-1)
    exit()

x = 0
y = 0

x = li[-1]
y = int(N / li[-1])

x -= 1
y -= 1

print(x+y)

Submission status: Wrong Answer

Solution code:
# N = m x n (m <= n) と表される時、m <= √n である
# この時の最大となるmを求める
import math

N = int(input())

limit = int(math.sqrt(N))
for i in reversed(range(1, limit)):
    if N % i == 0:
        m = i
        n = int(N / i)
        print((m - 1) + (n - 1))
        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())

a = 1
b = 1

fct = factorization(n)

for x, y in fct:
    for _ in range(y):
        if a <= b:
            a *= x
        else:
            b *= x

print(a+b-2)

Submission status: Wrong Answer

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

    # divisors.sort()
    return divisors
a=make_divisors(n=int(input()))
ans=([sum(a[k:k+2]) for k in range(0,len(a),2)])
print(min(ans)-2)

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):
    X[ind]*=k
    ind=(ind+1)%2
ans= sum(X)-2
if ans==0:
    ans=N-1
print(ans)

Submission status: Wrong Answer

Solution code:
def is_prime(n):
    if n < 2:
        return False

    if n == 2:
        return True

    if n % 2 == 0:
        return False

    i = 3
    while i * i <= n:
        if n % i == 0:
            return False
        i += 2

    return True


def factors(n):
    div = 2
    ans = []
    while n != 1:
        if n % div == 0:
            ans.append(div)
            n //= div
        else:
            div += 1
    return ans


def solve(n):
    if is_prime(n):
        return n - 1

    ans = [1, 1]
    for f in factors(n):
        smaller_i = 0 if ans[0] <= ans[1] else 1
        ans[smaller_i] *= f

    return sum([a - 1 for a in ans])


n = int(input())
print(solve(n))

Submission status: Wrong Answer

Solution code:
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    t = n
    mt = 10 ** 20
    for i in range(2, int(n ** 0.5) + 1):
        if t % i == 0:
            mt = min(mt, (i - 1) + (t // i - 1))
    print(mt)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
N = int(input())

res = "No"

if (N <= 81):
    x = 1
    while(x < 10):
        a = N // x
        if (a >= 1 and a <= 9 and a * x == N):
            res = "Yes"
        x += 1

print(res)