Problem:


Score : 300 points

Problem Statement

Takahashi is standing on a multiplication table with infinitely many rows and columns.

The square (i,j) contains the integer i \times j. Initially, Takahashi is standing at (1,1).

In one move, he can move from (i,j) to either (i+1,j) or (i,j+1).

Given an integer N, find the minimum number of moves needed to reach a square that contains N.

Constraints

2 \leq N \leq 10^{12}

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the minimum number of moves needed to reach a square that contains the integer N.

Sample Input 1

10

Sample Output 1

5

(2,5) can be reached in five moves. We cannot reach a square that contains 10 in less than five moves.

Sample Input 2

50

Sample Output 2

13

(5, 10) can be reached in 13 moves.

Sample Input 3

10000000019

Sample Output 3

10000000018

Both input and output may be enormous.



Sample input:
10


Sample output:
5

Submission status: Wrong Answer

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

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

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

    return arr

N = int(input())

arr = factorization(N)

#print(arr)

li = []

for i in arr:
    for j in range(i[1]):
        li.append(i[0])
#print(li)
while(len(li) > 2):
    li.sort()
    li.append(li[0]*li[1])
    li.pop(0)
    li.pop(0)
    print(li)
#print(li)
if(len(li) == 1):
    print(li[0]-1)
else:
    print(li[0]+li[1]-2)

Submission status: Wrong Answer

Solution code:
n = int(input())
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()
p = len(divisors)//2

print (divisors[p] + divisors[p -1] -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())

maxStep = N-1

divs = make_divisors(N)

for i in range(round(len(divs)/2)):
	if 2*i+1 >= int(len(divs)):
		print("yes")
		A=divs[2*i]
		B=divs[2*i]
	else:
		A=divs[2*i]
		B=divs[2*i+1]
	if  A-1 + B-1 < maxStep:
		maxStep = A-1 + B-1

print(maxStep)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
i = 1
j = 1
a = 0
change_dir = 0
while n == i * j:
    print (a)
else:
    if change_dir == 0:
        i = i + 1
        change_dir = 1
        a = a + 1
    else:
        j = j + 1
        change_dir = 0
        a = a + 1

Submission status: Wrong Answer

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

a = prime_factorize(N)
# print(a)
a.sort()

if len(a) == 1:
    a.append(1)
    a.sort()

while len(a) > 2:
    a1 = a.pop(0)
    a2 = a.pop(0)
    
    a.append(a1 * a2)
    a.sort()
    
# print(a)

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

Submission status: Wrong Answer

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

for p in reversed(range(1, s)):
#     print(p)
    if N % p == 0:
        p, q = p, N // p
        print(p + q - 2)
        break

Submission status: Wrong Answer

Solution code:
import math

def divisor_generator(n):
    large_divisors = []
    for i in range(1, int(math.sqrt(n) + 1)):
        if n % i == 0:
            yield i
            if i*i != n:
                large_divisors.append(n // i)
    for divisor in reversed(large_divisors):
        yield divisor

n = int(input())


divs = list(divisor_generator(n))
l = len(divs) - 1
best = 2 if n == 1 else min([divs[i] + divs[l-i] for i in range(len(divs)>>1)] )

print(best-2)

Submission status: Wrong Answer

Solution code:
import collections
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
  
primelist=make_divisors(A)
S = primelist[-1]
G = int(A/S)
print(primelist,S,G)
print((G-1)+(S-1))

Submission status: Wrong Answer

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

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

    return 1

flag = is_prime(n)

if flag == 1:
    print(n-1)
else:
    if math.sqrt(n) == n/math.sqrt(n):
        print(int((math.sqrt(n)-1)*2))
    else:
        m = int(n/2)
        for i in reversed(range(2,m)):
            if n % i == 0:
                l = i
                break
        s = int((n/l)+l-2)
        print(s)

Submission status: Wrong Answer

Solution code:
import numpy as np
from collections import Counter

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

N = int(input())
factors = np.array(prime_factorize(N))
counter = Counter(factors)
half = {k:v//2 for k, v in counter.items()}
smaller = np.array([k**v for k, v in half.items()]).prod()
larger = N//smaller
dist = smaller+larger-2
print(dist)

Submission status: Wrong Answer

Solution code:
a = int(input())

n =a
b = []
for i in range(2,int(-(-a**0.5//1))+1):
    if a % i ==0:
        b.append(i)
        a = a/i
        while a%i==0:
            b.append(i)
            a = a/i
if a != 1:
    b.append(a)
if b == []:
    b.append(a)

if len(b)==1:
    print(int(b[0]-1))
elif len(b)==2:
    print(int(b[0]+b[1]-2))
else:
    r = b[-1]
    s = b[-2]
    for j in range(2,len(b)):
        i = -1-j
        if r>s and s*b[i]>n/r/b[i]:
            s = s*b[i]
        else:
            r = r * b[i]
    print(int(r+s-2))

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(-2))
print(sum(res) - 2)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools
def p(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())
p=p(n)
if len(p)==1:
    print(p[0]-1)
    exit()
a=10**12
b=1
for i in p:
    b*=i
pp=int(len(p)**0.5) 
for k in range(pp,min(len(p),pp+5)):    
    for i in itertools.combinations(p, k):
        c=np.prod(i)
        a=min(a,c+b//c)
print(a-2)

Submission status: Wrong Answer

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

ans = N-1

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


print(ans)

Submission status: Wrong Answer

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

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

if is_prime(n) == True:
    print(n-1)
else:
    ls = (make_divisors(n))
    print(ls)
    if (n / ls[-1]) == ls[-1]:
        print(ls[-1]+ls[-1]-2)
    else:
        print(ls[-1]+ls[-2]-2)

Submission status: Wrong Answer

Solution code:
import math

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

    # divisors.sort()
    return divisors

n = int(input())

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

l = make_divisors(n)

ans = n-1
for i in range(0, len(l)-1):
  a = l[i]
  b = l[i+1]
  if a * b == n:
    ans = min(ans, (a+b-2))

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = []
m = n**0.5
q = m // 1
r = int(q)
for i in range(2,r+1):
    for j in range(2,r+1):
        l.append(i*j)
if n not in l:
    ans = n-1
else:
    lf = []
    for k in range(1, n+1):
        if n % k == 0:
            lf.append(k)
        i = lf[len(lf) // 2 - 1]
        j = lf[len(lf) // 2]
        ans = i + j - 2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = 0
b = 0
list = []
for a in range(1,n+1):
    b = n/a
    if n%a == 0 :
        list.append(a+b-2)
print(min(list))

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
a=1
mini=1e+12
while(n%2==0):
    a*=2
    n//=2
    if a-1+n-1<mini:
          mini=a-1+n-1
for i in range(3,int(math.sqrt(n))+1):
    while n%i==0:
        a*=i
        n//=i
        if a-1+n-1<mini:
          mini=a-1+n-1
print(mini)

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 optimization(tmp):
    while len(tmp) >= 3:
        if tmp[0] * tmp[1] <= tmp[1] * tmp[2]:
            tmp[0] = tmp[0] * tmp.pop(1)
        else:
            tmp[1] = tmp[1] * tmp.pop(2)
    return tmp


n = int(input())

tmp = prime_factorize(n)
if len(tmp) == 1:
    print(tmp[0] - 1)
elif len(tmp) == 2:
    print(sum(tmp) - 2)
else:
    answer = optimization(tmp)
    print(sum(answer) - 2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
a=1
mini=1e+12
while(n%2==0):
    a*=2
    n//=2
for i in range(3,int(math.sqrt(n))+1):
    while n%i==0:
        a*=i
        n//=i
print(a-1+n-1)

Submission status: Wrong Answer

Solution code:
import math
import itertools
n = int(input())
L=[1]
for i in range(2, n+1):
    while n%i==0:
        L.append(i)
        n = n/i

if(len(L)==1):
    L.append(n)

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

Submission status: Wrong Answer

Solution code:
N = int(input())

def divisor(n):  # nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(n // i)
        i += 1
    table = list(set(table))
    return table

yakusuu = divisor(N)
yakusuu.sort()

answer = N - 1
for i in yakusuu:
    if i != 1:
        new_answer = (i-1) + ((N / i)-1)
        if answer > new_answer:
            answer = new_answer
print(answer)

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):
        if i % 2 == 0:
            A *= pf[n - 1 - i] ** int(power[n - 1- i] / 2)
            B *= pf[n - 1 - i] ** (power[n -1- i] - int(power[n - 1- i] / 2))
        else:
            B *= pf[n - 1 - i] ** int(power[n - 1- i] / 2)
            A *= pf[n - 1 - i] ** (power[n -1- i] - int(power[n - 1- i] / 2))
    return (A - 1) + (B - 1)

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

Submission status: Wrong Answer

Solution code:
from functools import reduce
from operator import mul

N = int(input())

def main():
    primes = prime_factorize(N)
    if len(primes) == 1:
        print(primes[0] - 1)
        return
    elif len(primes) == 2:
        print(primes[0] + primes[1] - 2)
        return

    a = 1
    b = 1
    length = len(primes)
    for i in range(0, length):
        if a <= b:
            a *= primes.pop(0)
        else:
            b *= primes.pop()

    print(a + b - 2)

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

main()

Submission status: Wrong Answer

Solution code:
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())
s = factorization(n) 
 
s_ = []
for i in range(len(s)):
    for j in range(s[i][1]):
        s_.append(s[i][0])
a = [n]
b = [1]
c = []
 
for i in range(len(s_)):
    a.append(a[i]/s_[i])
    b.append(b[i]*s_[i])
for j in range(len(a)):
    c.append(a[i]+b[i]-2)
 
print(int(min(c)))

Submission status: Wrong Answer

Solution code:
n=int(input())
a = []
for i in range(1, int(n**0.5)+1):
  if n % i == 0:
    a.append(i)
    if i != n // i:
      a.append(n//i)
indx = len(a)//2
b = list(map(int,set(a)))
anc =100000000000000
for l in range(len(b)//2):
  if (n/b[l]+b[l])<anc:
    anc = (n/b[l]+b[l])
print(int(anc-2))

Submission status: Wrong Answer

Solution code:

import math

N = int(input())

#nの素因数分解を行いリストを返す
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)

    divisors.sort()
    return divisors

li = make_divisors(N)

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

if len(li) % 2 == 0:
    ind = int(len(li) / 2)
else:
    ind = int(len(li) / 2 + 1)

x = li[ind]
y = int(N / x)

x -= 1
y -= 1

print(x+y)

Submission status: Wrong Answer

Solution code:
n = int(input())

result = n
a = 1
b = n

for j in range(2, n//2):
  if n % j == 0:
    if j + n/j < result:
      a = j
      b = int(n/j)
      
if a == 1:
  print(n-1)
else:
  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())
F = [1]
for i, j in factorization(n):
    for _ in range(j):
        F.append(i)
R = []
tmp = F[0]
R.append(tmp)
for i in range(1, len(F)):
    tmp *= F[i]
    R.append(tmp)
L = []
tmp = F[-1]
L.append(tmp)
for i in reversed(range(len(F) - 1)):
    tmp *= F[i]
    L.append(tmp)
L = list(reversed(L))
ans = 9999999999999
for i in range(len(R) - 1):
    r = R[i]
    l = L[i+1]
    tmp = (r-1) + (l-1)
    if tmp < ans:
        ans = tmp
        a = r
        b = l
print(ans)

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())
if len(factorization(n))==1:
    print(n+1-2)
else:



    for i in range (1, 10**12):
        if n <= i**2:
            m = i
            break

    for i in range(0,m//2+1):
        for j in range(0,m//2+1):
            if (m-i-j)*(m+i) == n:
                print(m-i-j+m+i-2)
                break

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

maxStep = N

divs = make_divisors(N)

for i in range(round(len(divs)/2)):
	if 2*i+1 >= int(len(divs)):
		print("yes")
		A=divs[2*i]
		B=divs[2*i]
	else:
		A=divs[2*i]
		B=divs[2*i+1]
	if  A-1 + B-1 < maxStep:
		maxStep = A-1 + B-1

print(maxStep)

Submission status: Wrong Answer

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

min_value = 1000000000000
data = int(input())
ng_flag = False
divisors_array = make_divisors(data)
for i in range(0, len(divisors_array)-1):
    if(i % 2 == 0):
        if divisors_array[i] + divisors_array[i+1] < min_value:
            if i == 1:
                min_value = divisors_array[i] + divisors_array[i+1] - 1
            else:
                min_value = divisors_array[i] + divisors_array[i+1] - 2
print(min_value)

Submission status: Wrong Answer

Solution code:
import heapq as h
import math
 
# a,b = map(int,input().split())
n = int(input())
# l = list(map(lambda x:-int(x),input().split()))


can = 'No'
for i in range(2,10):
  if ((n%i) == 0):
    can = 'Yes'
    # right = n/i
    # if (1<=right) and (right<=9):
    #   can = 'Yes'

if can == 'Yes':
  # divides = []
  for i in range(2,n):
    if ((n%i) == 0):
      right = int(n/i)
      if i > right:
        print(int(i+right-2))
        break
      # divides.append(str(int(i))+'×'+str(right))
elif math.sqrt(n).is_integer():
  print(int(math.sqrt(n)*2-2))
else:
  print(n-1)

Submission status: Wrong Answer

Solution code:
c=int(input())
count=1
ans=10000000000000
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
d=list(prime_decomposition(c))
for k in range(len(d)):
    if k%2==0:
        count*=d[k]
        c=int(c/d[k])
    else:
        count*=d[len(d)-1-int(k/2)]
        c=int(c/d[len(d)-1-int(k/2)])
    if ans>count+c:
        ans=count+c
print(ans-2)

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

   # if arr==[]:
   #    arr.append([n, 1])
   arr=list(itertools.chain.from_iterable(arr))
   a=1
   b=1
   s=0
   # print(arr)
   for i in range(len(arr)):
      if i % 2 !=0:
         b = b*arr[i]
      else:
         a=a*arr[i] 
   s=(b-1)+(a-1)
   return s
   # return [a,b]


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

   print(a)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools
def p(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())
p=p(n)
if len(p)==1:
    print(p[0]-1)
    exit()
a=10**12
b=1
for i in p:
    b*=i
pp=int(len(p)**0.5) 
for k in range(pp,pp+4):    
    for i in itertools.combinations(p, k):
        c=np.prod(i)
        a=min(a,c+b//c)
print(a-2)

Submission status: Wrong Answer

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

ans = N-1

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


print(ans)

Submission status: Wrong Answer

Solution code:

N = int(input())

factor = []

tmp = int(N**0.5) + 1
for num in range(2,tmp):
    while N % num == 0:
        N //= num
        factor.append(num)

factor.append(N)

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

print(A+B-2)

Submission status: Wrong Answer

Solution code:
import math
import itertools
n = int(input())
L=[1]
for i in range(2, int(math.sqrt(n))+3):
    while n%i==0:
        L.append(i)
        n = n/i

if(len(L)==1):
    L.append(n)

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

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


def main():
  x = int(input())
  factorized = factorization(x)
  i = 0
  a = 1
  b = 1
  for num in factorized:
    if i % 2 == 0:
      a = a * num
    else:
      b = b * num
    i += 1
  result = a - 1 + b - 1
  return result
print(main())

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
m=int(np.ceil(np.sqrt(n)))
l=[]

for i in range(1,m,1):
    if n%i==0:
        a=i+(n/i)
        l.append(a)
        
c=int(min(l))
print(c-2)

Submission status: Wrong Answer

Solution code:
import math

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

    # divisors.sort()
    return divisors

n = int(input())
l = make_divisors(n)

ans = n-1
for i in range(0, len(l)-1):
  a = l[i]
  b = l[i+1]
  if a * b == n:
    ans = min(ans, (a+b-2))
  
print(ans)

Submission status: Wrong Answer

Solution code:
M = int(input())

def factorization(n):  # 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])
    if arr == []: # ｎが1のとき
        arr.append([n])
    return arr

import itertools
insu = list(itertools.chain.from_iterable(factorization(M)))
insu.sort()

if len(insu) == 1:
    print(insu[0]-1)
    exit()
while len(insu) > 2 :
    min = insu[0] * insu[1]
    insu = insu[2:]
    insu.append(min)
    insu.sort()

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

Submission status: Wrong Answer

Solution code:
n = int(input())
#a ,b  = list(map(int,input().split()))
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
list = sorted(prime_factorize(n),reverse = True)
a,b = 1,1
for i in range(len(list)):
    if a <= b:
        a *= list[i]
    else:
        b *= list[i]
print(a+b-2)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools
def p(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())
p=p(n)
if len(p)==1:
    print(p[0]-1)
    exit()
a=10**12
b=1
for i in p:
    b*=i
pp=int(len(p)**0.5) 
for k in range(pp,pp+3):    
    for i in itertools.combinations(p, k):
        c=np.prod(i)
        a=min(a,c+b//c)
print(a-2)

Submission status: Wrong Answer

Solution code:
import sys


n = int(input())

cost = sys.maxsize
tmp = 0
k = int(n/2)
for i in range(1,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:
N=int(input())
c=[]
d=[]
for i in range(1,10**6):
  if (N%i)==0 and (int(N/i)-i)>=0:
    c.append(int(N/i)-i)
    d.append(int(N/i))

for l in range(0,len(c)):
  if min(c)==c[l] and len(c)>1:
    m=N/d[l]
    print(int((m-1)+(d[l]-1)))
  elif len(c)==1:
    print(N-1)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
sq = math.floor(pow(n, 0.5))
flg = False
for i in range(2, n):
    if n % i == 0:
        flg = True
        break
if flg:
    print(sq * 2 - 1)
else:
    print(n - 1)

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())
temp = 1

n = factorize(n)

n.sort()
last = n.pop(-1)
for i in n:
    temp = temp * i
print((last-1)+ (temp-1))

Submission status: Wrong Answer

Solution code:
import math

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

    # divisors.sort()
    return divisors

n = int(input())
l = make_divisors(n)

ans = 999999999999999999
for i in range(0, len(l)-1):
  a = l[i]
  b = l[i+1]
  if a * b == n:
    ans = min(ans, (a+b-2))
  
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a = []
for i in range(1, int(n**0.5)+1):
  if n % i == 0:
    a.append(i)
    if i != n // i:
      a.append(n//i)
indx = len(a)//2
b = list(map(int,set(a)))
anc =10000000000000 
for l in range(len(b)//2):
  if (n/b[l]+b[l])<anc:
    anc = (n/b[l]+b[l])
print(int(anc-2))

Submission status: Wrong Answer

Solution code:
c=int(input())
count=1
ans=10000000000000
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
d=list(prime_decomposition(c))
print(d)
for k in range(len(d)):
    if k%2==0:
        count*=d[k]
        c=int(c/d[k])
    else:
        count*=d[len(d)-1-int(k/2)]
        c=int(c/d[len(d)-1-int(k/2)])
    if ans>count+c:
        ans=count+c
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
#lst = prime_factorize(N)
lst = make_divisors(N)
lst.sort()
#print(lst)
if len(lst) == 2:
    print(lst[-1] - 1)
else:
    print(lst[len(lst)//2] + lst[len(lst) // 2 - 1] - 2)

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, 1])

   # if arr==[]:
   #    arr.append([n, 1])
   arr=list(itertools.chain.from_iterable(arr))
   a=1
   b=1
   s=0
   for i in range(len(arr)):
      if i % 2 !=0:
         b = b*arr[i]
      else:
         a=a*arr[i] 
   s=(b-1)+(a-1)
   return s
   # return [a,b]


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

   print(a)

Submission status: Wrong Answer

Solution code:
import math
def fact(n):
  i = 1
  l=[]
  while i <= math.sqrt(n):
    if (n % i == 0) : 
      if (n / i == i) : 
        l.append(i) 
      else : 
        l.append(i)
        l.append(n//i)
    i = i + 1
  return l

n=int(input())
l=fact(n)
xx=0
mini=10000000000000
for i in l:
  for j in l:
    if i!=j and (i*j)==n:
      if abs(i-j)<mini:
        mini=abs(i-j)
        xx=(i-1)+(j-1)
print(xx)


'''
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
'''

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):
  b.append(a.pop(0))
if prod(a) < prod(b) and len(b) > 1:
  a.append(b.pop(-1))
  
print(prod(a)-1 +prod(b)-1)

Submission status: Wrong Answer

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

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

if is_prime(n) == True:
    print(n-1)
else:
    ls = (make_divisors(n))
    ans = (ls[round(len(ls)/2)-1])
    ans2 = (ls[round(len(ls)/2)])
    print(ans+ans2-2)

Submission status: Wrong Answer

Solution code:
N = int(input())

def divisor(n):  # nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(n // i)
        i += 1
    table = list(set(table))
    return table

yakusuu = divisor(N)
yakusuu.sort()

answer = N - 1
for i in yakusuu:
    if i != 1:
        new_answer = (i-1) + ((N / i)-1)
        if answer > new_answer:
            answer = new_answer
        else:
            break
print(answer)