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 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:
a = input()
a = int(a)
a1 = int(a/2)
n = a

for i in range(1, a1):
    if a % i == 0:
        b = int(a / i)
        n1 = i + b - 2
        n = min(n , n1)

print(n)

Submission status: Wrong Answer

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

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)
        cost = min(tmp,cost)
        tmp = 0

print(cost-2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

    return arr

N=int(input())
pfa = factorization(N)
if len(pfa) >= 4:
    topn = len(pfa)//2-1
    tmpa = pfa[:topn]
    print(tmpa)
    a = reduce(lambda x,y:x*y,tmpa)*pfa[-1]
    b = N //a
    print(a,b)
    print(a+b-2)
elif len(pfa) == 3:
    a = reduce(lambda x,y:x*y,pfa[:2])
    b = N // a
    print(a+b-2)
else:
    print(sum(pfa)-2)

Submission status: Wrong Answer

Solution code:
def division(n):
  factors = []
  tmp = int(n**0.5) + 1
  for num in range(2,tmp):
    while n % num == 0:
      n = n // num
      factors.append(num)
  if not factors:
    return [1, n]
  else:
    factors.append(n)
    return factors

def multiple(arr):
  new_arr = []
  mul = arr[0] * arr[1]
  del arr[0:2]
  arr.append(mul)
  arr.sort()
  return arr


input = int(input())
factors = division(input)
while len(factors) != 2:
  factors = multiple(factors)
answer = factors[0] + factors[1] - 2
print(answer)

Submission status: Wrong Answer

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

numDivList = make_divisors(num)
midNum = len(numDivList) // 2

ans = 0
if len(numDivList) % 2 == 0:
	ans = numDivList[midNum-1] + numDivList[midNum] -2
else:
	ans = numDivList[midNum-1] * 2 -2

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

# [[素因数,数]]を出力
def fctr1(n):
    f = []
    c = 0
    r = int(n ** 0.5)
    for i in range(2, r + 2):
        while n % i == 0:
            c += 1
            n = n // i
        if c != 0:
            f.append([i, c])
            c = 0
    if n != 1:
        f.append([n, 1])
    return f


# fact = factorization(n)
fact = fctr1(n)
# fact.sort()

# max_y = fact[-1][0]
# max_y = fact[-1][0] ** fact[-1][1]
# ans = max_y + n // max_y - 2

ans = 10 ** 12 + 1000

for i in range(len(fact)):
    for j in range(fact[i][1]):
        temp = fact[i][0] ** (j + 1)
        temp = temp + n // temp
        ans = min(ans, temp)

print(ans-2)

Submission status: Wrong Answer

Solution code:
pf = []
m = int(input())
tmp = 0
for i in range(2, int(m ** 0.5) + 1):
	while m % i == 0:
		pf.append(i)
		m //= i
if m > 1:
	pf.append(m)
L = len(pf)
if L == 1:
	print(pf[0]-1)
elif L == 2:
	print(pf[0] + pf[1] - 2)
else:
	maxva = 1
	count=0
	while(count<L-2):
		for i in range(count, L-1):
			maxva = maxva * pf[i]
		M = pf[L-1]
		if maxva > M:
			pf[L-1] = M*pf[count]
		else:
			pf[L-2] = pf[L-2]*pf[count]
		count += 1
	sum = pf[L-1] + pf[L-2] - 2
	print(sum)

Submission status: Wrong Answer

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

keep = copy.copy(N)

yaksuu = []

a = 2

while N >= a:
    if N%a == 0:
        N /= a
        yaksuu.append(a)
    else:
        a += 1


yaksuu.append(N)

now = 1

ans = 100000000000000

for i in range(0,len(yaksuu)):
    now *= yaksuu[i]
    keep /= yaksuu[i]
    if now + keep -2 <= ans: ans = ans = now + keep -2

print(int(ans))

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)
# print(a)
m=len(a)
# print(m)

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):
# 2 2 2 3 5 =120
# 2*5  = 10
# 2*3 * 2 = 12
#     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]*a[4]
    c=a[1]*a[6]*a[3]
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):
    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):
    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=c*a[int(m/2)]*a[int(m/2)+2]
    c=c*a[int(m/2)+1]
print (b+c-2)

Submission status: Wrong Answer

Solution code:
import math
def isPrime(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n % k == 0:
            return False
    return True
def searchMulti(n):
    i, j = 0, 0
    for x in range(2, n):
        if n % x == 0:
            y = n / x
            print(x, y)
            if y - x > 0:
                i = x
                j = y 
    return i, j
n = int(input())
if isPrime(n) == True:
    print(n-1)
else:
    i, j = searchMulti(n)
    print(i, j)
    print((i-1)+(j-1))

Submission status: Wrong Answer

Solution code:
N = int(input())
from functools import reduce
def factorize(n):
    b = 2
    fct = [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
A = factorize(N)

ans = 999999999999
for i in range(1,len(A)):
    xx = 1
    yy = 1
    for a in A[0:i]:
        xx *= a
    for a in A[i:]:
        yy *= a
    print(xx,yy)
    ans = min(ans,xx+yy-2)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = 2
fct = []
while b * b <= n:
    while n % b == 0:
        n //= b
        fct.append(b)
    b = b + 1
if n > 1:
    fct.append(n)
if len(fct) <= 2:
    print(sum(fct)-2)
else:
    x = fct[0]
    y = fct[len(fct)-1]
    xx = x
    yy = y
    for i in range(1, len(fct) - 1):
        if x <= y:
            xx = x * fct[i]
        if x > y:
            yy = y * fct[i]
    
    print(xx + yy - 2)

Submission status: Wrong Answer

Solution code:
pf = []
m = int(input())
tmp = 0
for i in range(2, int(m ** 0.5) + 1):
	while m % i == 0:
		pf.append(i)
		m //= i
if m > 1:
	pf.append(m)
L = len(pf)
if L == 1:
	print(pf[0]-1)
elif L == 2:
	print(pf[0] + pf[1] - 2)
else:
	maxva = 1
	count=0
	while(count<L-2):
		for i in range(count, L-1):
			maxva = maxva * pf[i]
		M = pf[L-1]
		if maxva > M:
			pf[L-1] = M*pf[count]
		else:
			pf[L-2] *= pf[count]
		count += 1
	sum = pf[L-1] + pf[L-2] - 2
	print(sum)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

sqrt_n = math.sqrt(n)

m = 1
for i in range(1, math.ceil(sqrt_n)):
    if n % i == 0:
        m = n / i

print(int(n / m + m - 2))

Submission status: Wrong Answer

Solution code:
import itertools
import functools
import operator
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

# def prod_dfs(a, p, n):
#     # print(a, p)
#     if p * n >= sqr:
#         # print(a, p, n, sqr)
#         return p
#     tmp = 0
#     prev = 0
#     for i, next_ in enumerate(a):
#         if prev == next_:
#             continue
#         prev = next_
#         tmp = max(prod_dfs(a[:i] + a[i+1:], p * n, next_), tmp)
#     return tmp

# def prod_dfs_(a):
#     tmp = 0
#     prev = 0
#     for i, next_ in enumerate(a):
#         if prev == next_:
#             continue
#         prev = next_
#         tmp = max(prod_dfs(a[:i] + a[i+1:], 1, next_), tmp)
#     return tmp

# prod = functools.partial(functools.reduce, operator.mul)

a = prime_factorize(N)
sqr = math.sqrt(N)

t = a.pop()

if len(a) == 1:
    print(N - 1)
elif len(a) == 2:
    print(a[0] + a[1] - 2)
else:
    ans = 10 * 6
    for i in range(2 ** len(a)):
        tmp = t
        for j in range(len(a)):
            if ((i >> j) & 1):
                tmp *= a[j]
        if abs(ans) > abs(sqr - tmp):
            ans = tmp - sqr

    print(int(ans + sqr + N // (ans + sqr) - 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

input_num = int(input())
factors = sorted(prime_factorize(input_num))

if len(factors) == 1:
    print(input_num - 1)
elif len(factors) > 2:
    while len(factors) != 2:
        tmp = factors
        tmp[0] = tmp[0] * tmp[1]
        tmp.pop(1)
        factors = sorted(tmp)
    
    print(factors[0] -1 + factors[1] - 1)
    
else:
    print(factors[0] -1 + factors[1] - 1)

Submission status: Wrong Answer

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


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

pfs = prime_factors(n)
#print(pfs)

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

Submission status: Wrong Answer

Solution code:
data = int(input())
     
ans = ""
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:
          if i > j:
            print(j)
          else:
            print(i)

Submission status: Wrong Answer

Solution code:
import sys

#+++++

def sp(value):
		ret_v=[]
		v=value
		for i in range(2, value):
			if v % i == 0:
				ret_v.append(i)
				v=v//i
				
				while v % i == 0:
					ret_v.append(i)
					v=v//i
					
			if i*i>v:
				ret_v.append(v)
				return (ret_v)
				
		ret_v.append(v)
		return (ret_v)

def main():
	a = int(input())
	bb=sp(a)
	ag=1
	bg=1
	for i,v in enumerate(bb[::-1]):
		if ag<=bg:
			ag=ag*v
		else:
			bg=bg*v

	print(ag+bg-2)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Wrong Answer

Solution code:
n = int(input())
for i in range (1, 10**12):
    if n <= i**2:
        m = i
        break
migi = -1
hida = 0
for j in range(0,m//2+1):
    if j % 2 == 0:
        migi += 1
    else:
        hida += 1
    for i in range(0,m//2+1):
        if (m-i-migi)*(m+i-hida) == n:
            print(m-i-migi+m+i-hida-2)
            break

Submission status: Wrong Answer

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

sosu_dict = {}
a = N
b = N
#print(int(math.sqrt(N+1)))
for i in range(1, int(math.sqrt(N+1))):
    if a % i == 0:
        sosu_dict[i] = int(a/i)
        b = a/i
 

if b > 1:
    sosu_dict[int(b)] = int(a/b)

#print(sosu_dict)

sum = 10 ** 15 +1
for key in sosu_dict:
    if (key + sosu_dict[key]) < sum:
        sum = key + sosu_dict[key]

print(sum-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

def f2(n):
    N = n
    a = []
    cnt=0
    while n % 2 == 0:
        cnt+=1
        # a.append(2)
        a.append([abs(N//(2**cnt)-(2**cnt)), N//(2**cnt), 2**cnt])
        n //= 2
    f = 3
    cnt=0
    while f * f <= n:
        if n % f == 0:
            F=f**cnt
        #     a.append(f)
            a.append([abs(N//F-F), N//F, F])
            n //= f
        else:
            f += 2
    if n != 1:
        # a.append(n)
        a.append([abs(N//n-n), N//n, n])
    return a

n = int(input())
# print(prime_factorize(n))

ans = f2(n)
ans.sort()
# print(ans)
if len(ans) == 1:
        print(n-1)
else:
        print(ans[0][1] + ans[0][2] - 2)
# for i in range(len(ans)):
#         if ans[i][1]*ans[i][2] == n:
#                 print(ans[i][1] + ans[i][2] - 2)
#                 exit()

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np

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

cnt = 0
i = 2
a = prime_factorize(n)
if len(a) == 1:
    a.append(1)
b = []
for i in range(1,len(a) // 2 + 2):
    b.append(list(itertools.combinations(a, i)))

m = 10**12
for i in range(len(b)):
    for j in range(len(b[i])):
        if j > 0:
            if b[i][j] != b[i][j-1]:
                c = np.prod(b[i][j])
                d = n // c
                if m > c+d:
                    m=c+d

print(m-2)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

# print(pf)

A = 1
B = 1
for i in pf:
  if A <= B:
    A *= i
  else:
    B *= i

ans = A + B - 2

pf.sort()

A = 1
B = 1
for i in pf:
  if A <= B:
    A *= i
  else:
    B *= i

ans = min(ans, A + B - 2)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

result = n - 1

count = 0

# if n % 2 == 0:
#     result = int(n / 2) + 0

# if n % 3 == 0:
#     result = int(n / 3) + 1

# if n % 4 == 0:
#     result = int(n / 4) + 2
 
i = 2
while i < n / i:
    if n % i == 0:
        result = int(n / i) + i - 2
    i += 1

print(result)

Submission status: Wrong Answer

Solution code:
import math


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

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

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

    return arr


n = int(input())
n_fact = factorization(n)

check = 0
for i in range(len(n_fact)):
    if n_fact[i][1] % 2 != 0:
        check = 1
        break

if len(n_fact) == 1:
	ans = n - 1
elif check == 0:
    ans = 2 * int(math.sqrt(n)) - 2
else:
    ans = 2 * int(math.sqrt(n)) - 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

ulim = pow(N, 1/2)
if ulim.is_integer():
    print(int(ulim -1))
else:
    ulim = int(ulim) + 1
#     print(ulim)

pnum = []
waru = 2
uflag = 0

while N > 1:
    aa = float(N / waru)
    if aa.is_integer():
        pnum.append(waru)
        N = int(aa)
    else:
        waru += 1
    if waru > ulim:
        if N >= ulim:
            pnum.append(N)
            uflag = 1
        break

# print(pnum)

raw = 1
col = 1



if uflag == 1:
    raw = pnum[-1]
    col = 1
    for j in range(len(pnum)-1):
        col *= pnum[j]
else:
    for i in range(1,len(pnum)+1):
        if raw <= col:
            raw *= pnum[-i]
        else:
            col *= pnum[-i]
        
print(raw-1 + col-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
temp = N//2
max_val1 = 0
max_val2 = 0
ans = 0
ans_temp = 1000000000000
for i in range(1, temp+1):
    if N % i == 0:
        max_val1 = i
        max_val2 = N // i
        ans = max_val1 + max_val2 - 2
        if ans < ans_temp:
            ans_temp = ans
        else:
            break
        #print(ans)
        #print(max_val1)
        #print(max_val2)

#print(ans)
print(ans)

Submission status: Wrong Answer

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

n = int(input())
x = pf(n)
x = sorted(x, reverse=True)

a, b = 1, 1
for i in x:
    if a*i<b*i:
        a *= i
    else:
        b *= i
print(a+b-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 = factorization(N)
ans =[]
for a in A:
  for i in range(1,a[1]+1):
    ans.append(N//a[0]+a[0]-2)

print(int(min(ans)))

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)
w = len(factor)
if w == 0:
    factor.append(n)
    w = 1
if w == 1:
    print(n - 1)
else:
    ans = 1000000000000
    for i in range(1, 2 ** w // 2):
        f2 = [1, 1]
        for j in range(w):
            f2[i & (2 ** j) == 0] *= factor[j]
        ans = min(ans, sum(f2) - 2)
        if ans < n ** 0.5 * 2.5:
            break
    print(ans)

Submission status: Wrong Answer

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

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

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

    return arr

def logic():
    a = 1
    b = 1
    for x in p:
        #print("a:{} b:{} t:{}".format(a, b, t))
        if a * x < t:
            a = a * x
        else:
            if a * x > b * x:
                b = b * x
            else:
                a = a * x
    return a, b


n = int(input())
p = factorizeFlat(n)
p.sort()
t = (n**0.5)//1

a1, b1 = logic()
p = p[::-1]
a2, b2 = logic()

if (a1 + b1 > a2 + b2):
    print(a2 + b2 - 2)
else:
    print(a1 + b1 - 2)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
a=0
b=0
t=n
for i in range(1,n):
	if n%i ==0:
		if t>(n/i)-i and t>0:
			t=(n/i)-i
			a=n/i
			b=i
			print(a)
if a<=1 or b==1:
	z=a+b-1
else:
	z=a+b-2
print(math.floor(z))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import itertools
 
def prime_factor(n):
    ass = np.array([1], dtype="int64")
    for i in range(2,int(n**0.5)+1):
        while n % i==0:
            ass = np.append(ass, i)
            n = n//i
    if n != 1:
        ass = np.append(ass, n)
    return ass

def main():
    input = sys.stdin.readline
    N = np.int64(input())
    ass = prime_factor(N)
    num = len(ass)
    if num == 2:
        ans = ass[0] - 1 + ass[1] - 1
    else:
        ans = N
        a = np.array(list(itertools.combinations_with_replacement(np.array([True, False]), num)))
        num_a = len(a)
        for j in range(num_a//2 - 1):
            j += 1
            u = np.prod(ass[a[j]], dtype="int64")
            v = np.prod(ass[~a[j]], dtype="int64")
            if ans >= u - 1 + v - 1:
                ans = u - 1 + v - 1
 
    print(ans)

if __name__ == '__main__':
    main()

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())
lst = prime_factorize(n)

if len(lst)==1:
    print(n-1)
    
else:
    num = [1,1]
    lst.sort(reverse = True)
    for i in range(len(lst)):
        if num[0] == num[1]:
            num[1] *= lst[i]
        elif 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:
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
  
def prod(n):
  result = 1
  for x in n:
    result *= x
  return result
  
a = prime_factorize(n)
b = [a.pop(-1)]


while prod(a) > prod(b):
  prev_result = prod(a) + prod(b)
  b.append(a.pop(a.index(min(a))))

  if prev_result < prod(a) + prod(b):
    a.append(b.pop(b.index(min(b))))

    break

print(prod(a)-1 +prod(b)-1)

Submission status: Wrong Answer

Solution code:
import itertools
import operator
import functools
import sys

def 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

target_list = factorize(int(input()))
loop=len(target_list)+1
ans=sys.maxsize


for i in range(loop):
    a=target_list[:i]
    b=target_list[i:]
    if len(a)>0:
        a=functools.reduce(lambda x,y:x*y,target_list[:i])
    else:
        a=1
    if len(b)>0:    
        b=functools.reduce(lambda x,y:x*y,target_list[i:])
    else:
        b=1
    ans=min(ans,a+b-2)

print(ans)

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())
ans = 0
cols = prime_factorize(n)
cols.sort(reverse=True)
a = [1, 1]
for col in cols:
  ma = min(zip(a, range(len(a))))[1]
  a[ma] = a[ma] * col

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

Submission status: Wrong Answer

Solution code:
n = int(input())

min = 10**12

for i in range(2,n):
  mod = n % i
  
  if mod != 0 : continue
  
  v1 = i
  v2 = int (n / i)
  
  move = ( v1 -1 ) + ( v2 - 1 )

  if move < min : 
    min = move
    

print(min)

Submission status: Wrong Answer

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

fact_arr=np.array(prime_factorize(num))
def GetDoubleFact(arr):
    _min=np.min(arr)
    arr=np.delete(arr,arr.argmin())
    sec_min=np.min(arr)
    arr=np.delete(arr,arr.argmin())
    arr=np.append(arr,_min*sec_min)
    return arr
if len(fact_arr)==1:
    print(fact_arr[0]-1)
else:
    while len(fact_arr)>2:
        fact_arr=GetDoubleFact(fact_arr)
    print(fact_arr[0]+fact_arr[1]-2)

Submission status: Wrong Answer

Solution code:
import math
N = int(input()) 
factor = []
tmp = int(math.sqrt(N)) + 1
list = range(2,tmp)
for num in list[::-1]:
    while N % num == 0:
        N //= num
        factor.append(num)
        factor.append(N)
    if not factor:
        factor.append(N)
        factor.append(1)
    else:
        pass
    break

f=sum(factor)-2
print(f)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np


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


def solve(N: int):

    fct_list = prime_factorize(N)

    result = 1e13

    if len(fct_list) == 2:
        x = fct_list[0]
        y = fct_list[1]

        print(x - 1 + y - 1)
    elif len(fct_list) == 1:
        x = fct_list[0]
        y = 1
        print(x - 1 + y - 1)
    elif len(fct_list) == 0:
        print(0)

    else:
        for i in range(1, len(fct_list) - 1):

            x = np.prod(fct_list[: i + 1])
            y = np.prod(fct_list[i + 1 :])

            result = min(result, x - 1 + y - 1)
        print(int(result))
    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())
import math
import itertools

def is_prime(n):
   if n == 1: return False
   for k in range(2, int(math.sqrt(n)) + 1):
      if n % k == 0:
         return False
   return True

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

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

   arr=list(itertools.chain.from_iterable(arr))

   a=arr[0]
   b=arr[-1]

   # print(arr,len(arr))
   for i in range(len(arr)-2):
      if len(arr)==2:
         a=arr[0]
         b=arr[-1]
      else:
         if a <= b:  
            a = a * arr[i+1]
         else:
            b = b * arr[i+1]

   # print("a,b:",a,b)
   return (b-1)+(a-1)
   # return [a,b]


if is_prime(n):
   print(n-1)
else:
   a=factorization(n)
   print(a)

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(int(a) - 2)

Submission status: Wrong Answer

Solution code:
#C
import numpy as np
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())

#print(2*np.sqrt(n))

#print(factorization(n))

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



#if len(f) == 1:
#    print(n-1)
#else:
#    print(int(round(2*np.sqrt(n))-1))


#print(f)
f.sort()

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

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



#print(a,b)

print(a+b-2)