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

l=prime_factorize(n)

x=y=1

for i in l[0::2]:
    x=i*x
for i in l[1::2]:
    y=i*y

print(x+y-2)

Submission status: Wrong Answer

Solution code:
n=int(input())
flag=0
max=999999999999999999999999999
for i in range(1,n):
    for j in range(1,n):

        
        if i*j==n:
            #print(i,j)
            if (i+j-2)<max:
                max=i+j-2
print(max)

Submission status: Wrong Answer

Solution code:
n = int(input())
def make_divisors(n):
    k = 0
    divisors = []
    for i in reversed(range(1, int(n**0.5)+1)):
        if n % i == 0:
            k = i

    # divisors.sort()
    return k
k = make_divisors(n)
kk = n // k
print(kk + k - 2)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
res = 10 ** 13
for i in range(1, int(math.sqrt(n))):
    a = n // i
    if a - n / i == 0:
        res = min(res, (i + a - 2))
print(res)

Submission status: Wrong Answer

Solution code:
ls = []

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

n = int(input())

if is_prime(n) == True:
    print(n-1)
else:
    for i in range(1,round(n/2)):
        if n % i == 0:
            ls.append(i)
        
        
    length = len(ls)
    ans = ls[length-1]
    ans2 = (round(n/ans))
    print(ans+ans2-2)

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

n=int(input())
m=prime_factorize(n)
M=m[::-1]
#print(m)
if m==[n]:print(n-1)
else:
    a=1;b=1;c=1;d=1
    for i in m:
        if a<=b:
            a*=i
        else:
            b*=i
    #print(a,b)
    for i in M:
        if c<=d:
            c*=i
        else:
            d*=i
    #print(c,d)
    print(min(a+b-2,c+d-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 main():
    n = int(input())
    l = prime_factorize(n)
    l.sort()
    if len(l)== 1:
        print(sum(l)-1)
    else:
        print(l[-1]-2+sum(l[:-1]))
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        # print(i)
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
                # print(n//i)
    return divisors
N = int(input())
tmp = make_divisors(N)
anss = []
for i in range(len(tmp)//2):
    anss.append(tmp[2*i] + tmp[2*i+1])
print(min(anss) - 2)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a = 1
b = n

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

print(int(a + b - 2))

"""
10
5

50
13

10000000019
10000000018

"""

Submission status: Wrong Answer

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

a=0
b=0
for i in range(int(math.sqrt(n)),2,-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:
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())
primes=[]
for x in factorization(N):
    for y in range(x[1]):
        primes.append(x[0])
ans=[1,1]
for x in reversed(primes):
    if ans[0]>= ans[1]:
        ans[1]*=x
    else:
        ans[0]*=x
print(ans[0]+ans[1]-2)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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
    
divisors = make_divisors(a)
b = max([i for i in divisors if i < a**(1/2)])
print(int(a/b + b - 2))

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = [1]*2
for i in range(1,n+1):
    if i * i < n:
        if n//i * i == n:
            ans[0] = i
            ans[1] = n//i
    else:
        break
print(sum(ans)-2)

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = n
for i in range(n):
  if n % (i+1) == 0:
    b = n/(i+1) + (i+1) -2
    if b < ans:
      ans = b
print(ans)

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)
    return divisors
X=make_divisors(N)
m=N
for i in range(len(X)//2):
    if X[2*i]+X[2*i+1] < m:
        m=X[2*i]+X[2*i+1]
if len(X)%2==1:
    if 2*X[-1]<m:
        m=2*X[-1]
print(m-2)

Submission status: Wrong Answer

Solution code:
n = int(input())


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

tmp = factorization(n) 

f_list = []
for one in tmp:
    for i in range(one[1]):
        f_list.append(one[0])
        
size = len(f_list)
a = 1
b = 1
for i in range(size):
    if i == 0:
        a = f_list.pop(size-i-1)
    else:
        if a > b:
            b *= f_list.pop(size-i-1)
        else:
            a *= f_list.pop(size-i-1)
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)[::-1]:
    if n % i == 0:
        print(i + int(n/i) - 2)
        exit()

Submission status: Wrong Answer

Solution code:
import math

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

minimum=n-1
for i in range(1,n2):
    if(n%i==0):
        minimum=min(minimum,(n//i-1)+(i-1))

print(minimum)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())


for i in range(2,n+1):
  if n %i == 0 and i*i > n:
    print(i + int(n/i) -2)
    break
else:
  print(n-1)

Submission status: Wrong Answer

Solution code:
N = int(input())


nums = []
denom = int(N ** .5)
while (1):
  if denom < 2:
    break
  while (N % denom == 0):
    N /= denom
    nums.append(denom)
  denom -= 1
nums.append(N)
x, y = 1, 1
for i, num in enumerate(nums):
  if i % 2 == 0:
    x *= num
  else:
    y *= num

print(int(x + y - 2))

Submission status: Wrong Answer

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

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

list1 = prime_factorize(n)
flag = 1

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

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
args = sys.argv
if len(args) == 2:
  from IPython import embed
  em = True
else:
  em = False
input = sys.stdin.readline
if em: sys.stdin = open('/dev/tty')
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 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
N = int(input())
import math
facts = []
for i in range(1, math.ceil(math.sqrt(N))):
  if N % i == 0:
    facts.append([i, N//i])
sums = []
for fact in facts:
  sums.append(sum(fact))
if em : embed()
print(min(sums)-2)

Submission status: Wrong Answer

Solution code:
# C
import itertools
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
ans = N - 1
l = list(itertools.combinations(make_divisors(N),2))
for i in l:
    if (i[0]*i[1] == N):
        num = i[0] + i[1] - 2
        ans = min(ans,num)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

for i in range(1000000, -1, -1):
    # print(i)
    if i < n**0.5 and n % i == 0:
        print(i + n // 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())
a = sorted(make_divisors(n))
if(len(a)/2 == 1):
  if(a[int(len(a)/2)-1]-2 == -1):print(n-1)
  else:a[int(len(a)/2)-1]-2
else:print(a[int(len(a)/2)] + a[int(len(a)/2)-1]-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)
    print(divs[-1] - 1 + divs[-2] - 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
a = 0

for i in range(1, int(N ** 0.5)):
    if(N % i == 0):
        a = i

ans = 0
if (a == 0):
    ans = N - 1
else:
    ans = (a-1) + (N//a - 1)

print(ans)

Submission status: Wrong Answer

Solution code:
#C
n = int(input())

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

x = prime_factorize(n)
o = 1
e = 1
for i in range(len(x)):
    if i % 2 == 0:
        o = o * x[i]
    else:
        e = e * x[i]
print(o + e - 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

def resolve():

    a = int(input())
    divisors = make_divisors(a)
    ans = divisors[-1] + divisors[-2] - 2
    print(ans)
    
resolve()

Submission status: Wrong Answer

Solution code:
N = int(input())
def divisor_list(num):
  ans = []
  for i in range(1, int(num**0.5)+1):
    if num % i == 0:
      ans.append(i)
      if i != num // i:
        ans.append(num//i)
  return ans
d_list = sorted(divisor_list(N))
d_list = d_list[1:]

ans = 10**13
for i in d_list:
  for j in d_list:
    if N == i*j and ans > i-1+j-1:
      ans = i-1+j-1
print(ans)

Submission status: Wrong Answer

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

prime = []

tN = N
for i in range(2, math.ceil(N**0.5)+1):
    while tN%i==0:
        tN //= i
        prime.append(i)
if tN!=1:
    prime.append(tN)

# print(prime)

x=1
y=1
for i,n in enumerate(prime):
    if i%2==0:
        x *= n
    else:
        y *= n

print(x+y-2)

Submission status: Wrong Answer

Solution code:
N = int(input())
min = 10000000000001
for i in range(1, 1000000):
    if N % i == 0:
        val = i + int(N / i) - 2
    if min > val:
        min = val

print(min)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = 10**15

def prime_factorize(n, unique=False):
    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 unique:
        return set(fct)
    else:
        return fct

n = int(input())
fact = prime_factorize(n)
fact.append(1)

ans = INF 
for item in fact:
    ans = min(ans, item + n // item - 2)
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math
N = int(stdin.readline().rstrip())
fact = 0
for i in range(1,math.ceil(math.sqrt(N))):
    if N % i == 0:
        fact = i
ans = fact + (N//fact) -2
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
j = N
count = N
for i in range(1, int(N/2)):
    if N % i == 0:
        j = int(N / i)
        if i + j - 2 < count:
            count = i + j - 2
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
k = []
for i in range(1,10*6+1):
    if N%i == 0:
        k.append((i-1)+(N//i)-1)
if len(k) == 0:
    print(N-1)
else:
    print(min(k))

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())
data=prime_factorize(N)
a=1
b=1
for i in range(len(data)-1,-1,-1):
  if a<b:
    a*=data[i]
  else:
    b*=data[i]

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

Submission status: Wrong Answer

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

print(min(arr)-2)

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

Submission status: Wrong Answer

Solution code:
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)
a,b=1,1
for i in p:
    a*=i
c=10**12
for i in p:
    a//=i
    b*=i
    c=min(c,a+b)
print(c-2)

Submission status: Wrong Answer

Solution code:
import sys
import math
import os

input = sys.stdin.readline

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

Submission status: Wrong Answer

Solution code:
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())
ls = prime_factorize(n)
 
for i in range(len(ls)):
  ans = []
  pair = n // ls[i]
  ans.append(ls[i] + n // ls[i] - 2)
 
ans.sort()
print(ans[0])

Submission status: Wrong Answer

Solution code:
# At ABC 144 C (300)
import math

def f(n):
    min_ = float("inf")
    end = int(math.sqrt(n))
    for div in range(1, end):
        if n % div == 0:
            r = n // div
            min_ = min(min_, (div - 1) + (r - 1))
    return min_

assert f(10) == 5
assert f(50) == 13
assert f(10000000019) == 10000000018

n = int(input())
ans = f(n)
print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    x = int(input())
    ans = 15000
    for i in range(x, 0, -1):
        if x % i == 0:
            q = (x / i) + i
            if q <= ans:
                ans = q
            else:
                print((int(x/i) - 1) + (i-1))
                break

Submission status: Wrong Answer

Solution code:
n = int(input())

n_divisors = []

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

len_nd = len(n_divisors)

print(n_divisors[len_nd - 1] + n_divisors[len_nd - 2] - 2)

Submission status: Wrong Answer

Solution code:
import math


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

    sqrt_n = math.ceil(math.sqrt(n))
    ans = -1
    for i in range(1, sqrt_n):
        q, mod = divmod(n, i)
        if mod == 0:
            ans = i + q - 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 i % 2 == 0:
        x *= a[i]
    else:
        y *= a[i]
print(x + y - 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())
arr = make_divisors(N)
num1 = arr[len(arr)//2 - 1]
num2 = N // num1
print(num1 + num2 - 2)

Submission status: Wrong Answer

Solution code:
N = int(input())
def divisor_list(num):
  ans = []
  for i in range(1, int(num**0.5)+1):
    if num % i == 0:
      ans.append(i)
      if i != num // i:
        ans.append(num//i)
  return ans
d_list = sorted(divisor_list(N))
d_list = d_list[1:]

for i in d_list:
  for j in d_list:
    if N == i*j:
      print(i-1+j-1)
      break
  else:
    continue
  break

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = 10**15

def prime_factorize(n, unique=False):
    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 unique:
        return set(fct)
    else:
        return fct

n = int(input())
print(n)
fact = prime_factorize(n)
fact.append(1)

ans = INF 
for item in fact:
    ans = min(ans, item + n // item - 2)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

T = trial_division(N)
T = sorted(T)

ans = N-1

for i in range(len(T)) :
    a = T[i]
    b = N//a
    ans = min(ans, a+b-2)
if len(T) == 1 :
    print(T[0]-1)
else :
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# import sys
import numpy as np
# sys.setrecursionlimit(200000)

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 = list(map(int, input().split(" ")))[0]

so = []
for n, i in (factorization(N)):
    for _ in range(i):
        so.append(n)
so = np.sort(so)[::-1]

A = 1
B = 1
for n in so:
    if A < B:
        A *= n
    else:
        B *= n
print(A + B - 2)

Submission status: Wrong Answer

Solution code:
N = int(input())
lis = []
for i in range(1,10**6):
  a = N/i
  if a.is_integer():
    lis.append(N/i+i-2)
if len(lis) == 0:
  print(N-1)
else:
  print(int(min(lis)))

Submission status: Wrong Answer

Solution code:
N = int(input())

x = -1
y = -1
for i in reversed(range(1, int(N**0.5))):
    if N % i == 0:
        x = i
        y = N // i
        break

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

Submission status: Wrong Answer

Solution code:
import bisect

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


divs = make_divisors(N)
i = bisect.bisect_left(divs, len(divs) / 2)
print(divs[i]-1 + divs[i + 1]-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
gcdlst = []
for i in range(1, int(N ** 0.5) + 1):
    if N % i == 0:
        gcdlst.append(i)
        if i != N // i:
            gcdlst.append(N // i)
gcdlst.sort()
tmplen = len(gcdlst) // 2
ans = gcdlst[tmplen] + gcdlst[tmplen - 1] - 2
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque,defaultdict
from fractions import gcd
from math import ceil
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 N():
    return int(sys.stdin.readline())
def NK():
    return map(int,sys.stdin.readline().split())
def LS_I():
    return [int(x) for x in sys.stdin.readline().split()]
def LS_S():
    return list(input())
def main():
    n = N()
    ls = prime_factorize(n)
    a,b = 1,1
    for i,num in enumerate(ls):
        if i%2==0:
            a *= num
        else:
            b *= num

    print(a+b-2)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = float(input())
A = int(N**(0.5))
max = 10**12
print(A)
for i in range(1,A+1):
    B = N/float(i)
    if B.is_integer():
        c = i+B-2
        if c<= max:
            max = c
print(int(max))

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())

d = set()
for i in range(1,int(N**0.5)+2):
  if N%i == 0:
    d.add(i)
    d.add(N//i)
d = list(d)
d.sort()

r = bisect.bisect_left(d,N**0.5)
#print(d[r-1],d[r])
print(d[r-1]+d[r]-2)

Submission status: Wrong Answer

Solution code:
a=int(input())
ans=a-1
for i in range(1,int(a**0.5)):
  if a % i ==0:
    ans=min(a,max(i-1,0) + max((a//i)-1,0))
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())
data=prime_factorize(N)
a=1
b=1
for i in range(len(data)):
  if a<b:
    a*=data[i]
  else:
    b*=data[i]

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

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

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

ans = (a-1) + (int(N/a)-1)

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

Submission status: Wrong Answer

Solution code:
def resolve():
    N = int(input())
    i = 1
    I = 1
    J = N
    while(i*i < N):
        if N % i == 0:
            I = i
            J = N // i
        i += 1
    print(I + J - 2)
resolve()

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

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

k = math.floor(math.sqrt(n))

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    x = int(input())
    ans = 15000
    for i in range(x, 0, -1):
        if x % i == 0:
            q = (x / i) + i
            if q < ans:
                ans = q
            else:
                print((int(x/i) - 1) + (i-1))
                break

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

factors = prime_factorize(N)
#print(factors)
a = 1
b = 1
for n in reversed(factors):
    if a <= b:
        a *= n
    else:
        b *= n
        
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

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

    x = prime_factorize(N)

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
x = int(math.sqrt(n))
y = 2 if n % 2 == 0 else 1

for i in range(3, x + 1, 2):
	if n % i == 0:
		y = n // i
		
print(y + (n // y) - 2)

Submission status: Wrong Answer

Solution code:
N = int(input())
k = []
for i in range(2,10*6+1):
    if N%i == 0:
        k.append((i-1)+(N//i)-1)
if len(k) == 0:
    print(N-1)
else:
    print(min(k))

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())

        divisors = self.make_divisors(N)
        print(divisors[-1] + divisors[-2] - 2)

    def make_divisors(self, n: int):
        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


# Run main
if __name__ == '__main__':
    AtCoder().main()

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_list = make_divisors(n)

print(div_list[-1] + div_list[-2] -2)

Submission status: Wrong Answer

Solution code:

# Setup
import sys
sys.setrecursionlimit(4100000)

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

a = int(input())
b = prime_decomposition(a)
b.sort()
if len(b) == 1:
    print(a-1)
else:
    ax = b[0]
    ay = b[1]
    for i in range(2,len(b)):
        if ax < ay:
            ax *= b[i]
        else:
            ay *= b[i]
    print(int(ax+ay-2))