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:
# ABC144c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

    # map(int,input().split())
    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
    aiu = prime_factorize(n)
    aiu.reverse()
    ans = [1, 1]

    for i in aiu:
        if ans[0] < ans[1]:
            ans[0] *= i
        else:
            ans[1] *= i
    print(sum(ans)-2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# ABC144c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

    # map(int,input().split())
    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

    ans = [1, 1]

    for i in prime_factorize(n):
        if ans[0] < ans[1]:
            ans[0] *= i
        else:
            ans[1] *= i
    print(sum(ans)-2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = 0
b = 0
import math
root_n = math.sqrt(n)
root_n = math.ceil(root_n)
for i in range(1,root_n):
    if(n % i == 0):
        if(i > a):
            a = i
b = n / a
print(int(a + b -2))

Submission status: Wrong Answer

Solution code:
import math 

n = int(input())
a=0
b=0
root_n  = math.sqrt(n)
#繰り上げ
root_n = math.ceil(root_n)
yakusuu =[]
for i in range(1,root_n):
    if(n%i == 0):
        yakusuu.append(i)
a = max(yakusuu)
b = n / a
print(int(a+b-2))

Submission status: Wrong Answer

Solution code:
import math

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

i, j = 10000000, 1000000
res  = 0
if is_prime(n):
    res = n - 1
else:
    for t in range(1, int(math.sqrt(n)) + 1):
        if n % t == 0:
            a, b = t, n//t
            if a + b < i + j:
                i, j = a, b
    res = i + j -2


print(res)

Submission status: Wrong Answer

Solution code:
import math

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

i, j = 0, 0
if is_prime(n):
    res = n - 1
else:
    d = n // 2
    for k in range(d-1, 1, -1):
        if n % k == 0:
            i = k
            j = n // k
            res = (i-1) + (j-1)
            break

print(i, j)
print(res)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
n = math.sqrt(N)
ans = 10 ** 12

for i in range(1 , math.ceil(n) + 1):
  if i * math.ceil(N / i) == N:
    count = (i - 1) + ((N / i) - 1)
    ans = min(ans , count)
    
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = []
for k in range(1,N):
    if k**2 < N:
        if N % k == 0:
            S.append(N/k+k-2)
        else:
            continue
    if k**2 >= N:
        break
print(int(min(S)))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

ans = 10000000020
for i in range(int(math.sqrt(N)), 0, -1):
    if N%i != 0:
        continue
    j = N/i
    ans = min(ans, i+j-2)
print(int(ans))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
ans = 10000000020
for i in range(int(math.sqrt(N)),0, -1):
    if i * i > N:
        break
    if N % i != 0:
        continue
    j = N // i
    ans = min(ans, i+j-2)

print(ans)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
ans = 10000000020
for i in range(1,int(math.sqrt(N)+1)):
    if i * i > N:
        break
    if N % i != 0:
        continue
    j = N / i
    ans = min(ans, i+j-2)

print(ans)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
ans = 10000000020
for i in range(1,int(math.sqrt(N)+1)):
    if N % i != 0:
        continue
    j = N / i
    ans = min(ans, i+j-2)

print(ans)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
ans = 10000000020
for i in range(1,int(math.sqrt(N)+1)):
    if i * i > N:
        break
    if N % i != 0:
        continue
    j = N // i
    ans = min(ans, i+j-2)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
dc_max = 1
temp = int(N**0.5)
for i in range(1,int(N**0.5)):
  if N%i == 0:
    dc_max = i

print((dc_max -1)+(N//dc_max-1))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

ans = 1e18
for i in range(1, int(math.sqrt(N))):
    if N%i != 0:
        continue
    j = N/i
    ans = min(ans, i+j-2)
print(int(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)
    divisors.sort()
    return divisors


r = make_divisors(n)
i = len(r)//2
j = i-1

print(r[i]-1+r[j]-1)

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
n=math.floor(N/2)
for i in range(n):
  if N%(n-i)==0:
    k=n-i
    l=N/k
    break
print(k+l-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

if __name__ == "__main__":
    li = list(map(int,input().split()))
    a=li[0]
    r=[]
    ret=a-1

    r=make_divisors(a)
    for i in range(0,int(len(r)/2)):
        if(r[i*2]+r[i*2+1]-2<ret):
            ret=r[i*2]+r[i*2+1]-2
    print(ret)

Submission status: Wrong Answer

Solution code:
import math
def main1():
    input_num = int(input())
    num_sqrt = int(math.sqrt(input_num))

    minimam = input_num
    for i in range(num_sqrt+1,0,-1):
        q, mod = divmod(input_num, i)
        if mod == 0:
            distance = q + i -2
            if minimam > distance:
                minimam = distance
    print(minimam)

Submission status: Wrong Answer

Solution code:
import math
input_num = int(input())
num_sqrt = int(math.sqrt(input_num))

minimam = input_num
for i in range(num_sqrt+1,0,-1):
    print(i)
    q, mod = divmod(input_num, i)
    distance = q + i -2
    if mod == 0 and minimam > distance:
        minimam = distance
print(minimam)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
half = math.floor(n**0.5)
#print(half)

num1 = 0
for i in range(half+1,0,-1):
  if n % i == 0 and 1 <=n/i<=9 :
    num1,num2 = i,n//i  
    #print("Yes")
    break

if not num1:
  print(n-1)
else:
  print(num1+num2-2)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
ans = 10000000020
for i in range(1,int(math.sqrt(N))):
    if i * i > N:
        break
    if N % i != 0:
        continue
    j = int(N / i)
    ans = min(ans, i+j-2)

print(ans)

Submission status: Wrong Answer

Solution code:

N = int(input())
ans = 10000000020
for i in range(1,N):
    if i * i > N:
        break
    if N % i != 0:
        continue
    j = int(N / i)
    ans = min(ans, i+j-2)

print(ans)

Submission status: Wrong Answer

Solution code:

a = int(input())
j=0
mass=100000000000001000000000
for i in range(9):
    j = j+1
    h=a/j
    if (h.is_integer()):    
        ans="Yes"
        mass2=j+h-2
        if(mass>=mass2):
            mass=mass2
    else:
        ans="No"
    

print(int(mass))

Submission status: Wrong Answer

Solution code:

a = int(input())
j=0
mass=100000000
for i in range(9):
    j = j+1
    h=a/j
    if (h.is_integer()):    
        ans="Yes"
        mass2=j+h-2
        if(mass>=mass2):
            mass=mass2
    else:
        ans="No"
    

print(int(mass))

Submission status: Wrong Answer

Solution code:
import math

def dictcheck(dict):
    min = 0
    for k,v in dict.items():
        if k == 1:
            min = v
            break
        elif min == 0:
            min=(int(k)-1)+(int(v)-1)
        elif min > (int(k)-1)+(int(v)-1):
            min = (int(k)-1)+(int(v)-1)
        else:
            continue
    print(min)

def main():
    N = int(input())
    i = 2
    tmpdict= {}
    while i <= math.sqrt(N):
        if N % i == 0:
            tmpdata = {i:N/i}
            tmpdict.update(tmpdata)
            i+=1
        else:
            i+=1
    if len(tmpdict)==0:
        tmpdata = {1:N-1}
        tmpdict.update(tmpdata)
    print(tmpdict)
    dictcheck(tmpdict)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math

def dictcheck(dict):
    min = 0
    for k,v in dict.items():
#        print("k:",k ,"+", "v:",v)
        if k == 1:
            min = (1) + (int(v) - 1)
        elif min == 0:
            min=(int(k)-1)+(int(v)-1)
        elif min > (int(k)-1)+(int(v)-1):
            min = (int(k)-1)+(int(v)-1)
        else:
            continue
    print(min)

def main():
    N = int(input())
    i = 2
    tmpdict= {}
    while i < math.sqrt(N):
        if N % i == 0:
            tmpdata = {i:N/i}
            tmpdict.update(tmpdata)
            i+=1
        else:
            i+=1
    if len(tmpdict)==0:
        tmpdata = {1:N-1}
        tmpdict.update(tmpdata)
#    print(tmpdict)
    dictcheck(tmpdict)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
res = float("inf")
for i in range(2, int(n**0.5)):
  if n % i == 0:
    res = i-1 + n//i -1
print(res if res != float("inf") else n - 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
res = float("inf")
for i in range(2, int(n**0.5)):
  if n % i == 0:
    res = i+n//i
print(res if res != float("inf") else n)

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())
count=0
a=prime_factorize(N)
count+=a[-1]+N/a[-1]-2

print(int(count))

Submission status: Wrong Answer

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

for i in range(2,N):
    if N%i==0:
        count=count+((N/i)-1)+1
        break;
    elif i==N-1:
        count=count+1
    count=count+1
print(int(count))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
q = []

for i in range(1,math.ceil(math.sqrt(N))):
    if N%i==0:
        q.append(i+int(N/i))

print(min(q)-2)

Submission status: Wrong Answer

Solution code:
import itertools

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

prime_list = factorization(N)
# print(prime_list)

ans = float('inf')

for p in itertools.product([0,1],repeat=len(prime_list)):
    # print(p)
    div = [1,1]
    for i in range(len(prime_list)):
        div[p[i]] *= prime_list[i]
    # print(div)

    if div[0] + div[1] - 2 < ans:
        ans = div[0] + div[1] - 2

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
diveiser = []
for i in range(1,N):
    if N%i == 0:
        diveiser.append(N/i)

for j in range(len(diveiser)-1):
    if N//(diveiser[j]) == diveiser[j+1]:
        print(diveiser[j]-1 + diveiser[j+1]-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
i = 2
breakloop = False
while True:
    print("W")
    for j in range(1,i):
        print(i*j)
        if i*j == N:
            ANS = i+j-2
            print(ANS)
            breakloop = True
            break
    if breakloop:
        break
    i += 1

Submission status: Wrong Answer

Solution code:
import math

raw = input()
N = int(raw)
n = math.sqrt(N)
listm = math.modf(n)
m = int(listm[1])

count = N - 1

for i in range(m,1,-1):
    if (N % i)==0:
        ans = i +(N % i) -2
        count = ans
        break

print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())

i=int(N**0.5);

while i>0:
    if N%i==0:
        i,j=(i,N/i)
        break
    i-=1

print(i+j-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):
		lst = []
		if n % i == 0:
			lst.append(i)
			if i != n // i:
				lst.append(n//i)
				divisors.append(lst)

	# divisors.sort()
	return divisors

print(sum(make_divisors(n)[-1])-2)

Submission status: Wrong Answer

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


def main():
    sc = Scan()
    n = sc.intarr()[0]
    minimum = n
    for i in range(1, n//2):
        if n % i == 0:
            cost = (n//i) + i-2
            if cost < n:
                minimum = cost
    print(minimum)


class Scan():

    def intarr(self):
        self.line = input()
        array = self.line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        self.line = input()
        array = self.line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()

Submission status: Wrong Answer

Solution code:
import math
x=int(input())
s=set()
y=int(math.sqrt(x))
for i in range(y,0,-1):
  print(i)
  if x%i == 0:
    a=i+x//i-2
    s.add(a)
    if min(s)-a <0:
      break
print(min(s))

Submission status: Wrong Answer

Solution code:
x=int(input())
s=set()

for i in range(x,1,-1):
  if x%i == 0:
    a=i+x//i-2
    s.add(a)
    if (min(s)-a <0)or(i==x/2):
      break
print(min(s))

Submission status: Wrong Answer

Solution code:
x=int(input())
s=set()
l=[i for i in range(1,x)]

for i in reversed(l):
  if x%i == 0:
    a=i+x//i-2
    s.add(a)
    if (min(s)-a <0)or(i==x/2):
      break
print(min(s))

Submission status: Wrong Answer

Solution code:
a=int(input())
c=a
if c<10000000:
    for i in range(10000000,2,-1):
        if a%i==0:
            b=a/i
            if i+b<c:
                c=i+b
    print(int(c-2))            
else:
    c=a-1
    print(int(c))

Submission status: Wrong Answer

Solution code:
a=int(input())
c=a
for i in range(10000000,2,-1):
    if a%i==0:
        b=a/i
        if i+b<c:
            c=i+b
print(int(c-2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a=int(input())
c=a+1
for i in range(1000000,2,-1):
    if a%i==0:
        b=a/i
        if i+b<c:
            c=i+b
print(int(c-2))

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = n - 1
a = 1
while a * a <= n:
  if n % a == 0:
    ans = min(ans, a - 1 + (n / a) - 1)
  a += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
count = 0
ans = []
for i in range(2, int(np.sqrt(n+1))):
    if n%i ==0:
        ans.append(i)
if len(ans) == 0:
    print(n-1)
else:
    tmp = max(ans)
    print(tmp+(n//tmp)-2)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
count = 0
ans = []
for i in range(2, int(np.sqrt(n+1))):
    if n%i ==0:
        count += 1
        break
if count == 0:
    print(n-1)
else:
    for i in range(1,n+1):
        for j in range(1, n+1):
            if i*j == n:
                ans.append(i+j-2)
    print(min(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = n
for i in range(1,n+1):
#  print(n,i)
  if n % i == 0:
    q = n / i
    qplusmod = q + i
#    print(n,i,qplusmod)
    if qplusmod < ans:
      ans = qplusmod
print(int(ans - 2))

Submission status: Wrong Answer

Solution code:
import math
b = input()
a = int(b)

sqA = int(math.sqrt(a))

for i in range(10000000):
    d = a / (sqA - i)
    if d.is_integer() == True:
        break


e = d + sqA - i - 2
print(d)
print(sqA + i)
print(int(e))

Submission status: Wrong Answer

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

seed = int(np.sqrt(N))
# 計算誤差を回避
while seed ** 2 < N:
    seed += 1
else:
    seed -= 1
min = 2 * seed - 2 + 1 #(走査を開始する)回目の試行


if N == 2:
    print(1)
elif N == 3 or N == 4:
    print(2)
elif N == 6:
    print(3)
elif N == 5 or N == 8 or N == 9:
    print(4)
else:
    #+3まで回さないとその行でカバーしないといけない左翼がカバーできない
    #-1を回さないとその行の最大をカバーできない
    for i in range(min - 1, min + 3): 
        if i % 2 == 0:
            num = int(i / 2) + 1
        else:
            num = int((i + 1) / 2) 
        for n in range(0, num + 1): #走査範囲は半分でいい
            x = (i + 1 - n) * (n + 1) 
            if x == N:
                print(i)
                break
        else:
            continue
        break
    else:
        print(N - 1)

Submission status: Wrong Answer

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

seed = int(np.sqrt(N))
# 計算誤差を回避
while seed ** 2 < N:
    seed += 1
else:
    seed -= 1
min = 2 * seed - 2 + 1 #(走査を開始する)回目の試行


#+3まで回さないとその行でカバーしないといけない左翼がカバーできない
#-1を回さないとその行の最大をカバーできない
for i in range(min - 1, min + 3): 
    if i % 2 == 0:
        num = int(i / 2) + 1
    else:
        num = int((i + 1) / 2) 
    for n in range(0, num + 1): #走査範囲は半分でいい
        x = (i + 1 - n) * (n + 1) 
        if x == N:
            print(i)
            break
    else:
        continue
    break
else:
    print(N - 1)

Submission status: Wrong Answer

Solution code:
import math
b = input()
a = int(b)

c = int(math.sqrt(a))

for i in range(10000000):
    d = a / (c + i)
    if d.is_integer() == True & i <= 1000:
        break
    if i > 1000:
        for j in range(1000000):
            f = a / (2 + j)
            if f.is_integer() == True:
                break
        break

if i > 1000:
    g = f + j
    print(int(g))
else:
    e = d + c + i - 2
    print(int(e))

Submission status: Wrong Answer

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

seed = np.sqrt(N)
min = 2 * int(seed) - 2 + 1 #(走査を開始する)回目の試行

#+3まで回さないとその行でカバーしないといけない左翼がカバーできない
#-1を回さないとその行の最大をカバーできない
for i in range(min - 1, min + 3): 
    if i % 2 == 0:
        num = int(i / 2) + 1
    else:
        num = int((i + 1) / 2) 
    for n in range(0, num + 1): #走査範囲は半分でいい
        x = (i + 1 - n) * (n + 1) 
        if x == N:
            print(i)
            break
    else:
        continue
    break
else:
    print(N - 1)

Submission status: Wrong Answer

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

seed = np.sqrt(N)
min = 2 * int(seed) - 2 + 1 #(走査を開始する)回目の試行

for i in range(min, min + 3): #+3まで回さないとその行でカバーしないといけない左翼がカバーできない
    if i % 2 == 0:
        num = int(i / 2) + 1
    else:
        num = int((i + 1) / 2) 
    for n in range(0, num + 1): #走査範囲は半分でいい
        x = (i + 1 - n) * (n + 1) 
        if x == N:
            print(i) 
            break
    else:
        continue
    break
else:
    print(N - 1)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
sqN = int(math.sqrt(N))
for i in range(sqN):
  if N % (sqN-i) == 0:
    print(int(N/(sqN-i)+sqN-i))
    break

Submission status: Wrong Answer

Solution code:
N=int(input())

ans=1e9
i=1
while i*i<=N:
    if (N%i==0):
       ans=min(ans,(i-1)+(N/i-1)) 
    i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
ans=10**12
for  x in range(1,int((N+1)**0.5)):
    if N%x==0:
        if (x+int((N/x)-2))<ans:
            ans=(x+int((N/x))-2)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
ans=10^12
for  x in range(1,N+1):
    if N%x==0:
        if (x+(N/x)-2)<ans:
            ans=x+(N/x)-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

a = int(input())

b = prime_factorize(a)

c = 1
d = 1
for i in range(len(b)):
    if i % 2 == 0:
        c *= b[i]
    else:
        d *= b[i]

print(c + d - 2)

Submission status: Wrong Answer

Solution code:
import math
b = input()
a = int(b)

c = int(math.sqrt(a))

for i in range(10000000):
    d = a / (c + i)
    if d.is_integer() == True:
        break
    if i > 1000:
        for j in range(1000000):
            f = a / (2 + j)
            if f.is_integer() == True:
                break
        break

if i > 1000:
    g = f + j
    print(int(g))
else:
    e = d + c + i - 2
    print(int(e))

Submission status: Wrong Answer

Solution code:
import math
b = input()
a = int(b)

c = int(math.sqrt(a))

for i in range(1000000):
    d = a / (c + i)
    if d.is_integer() == True:
        break

e = d + c + i - 2
print(int(e))

Submission status: Wrong Answer

Solution code:
import math
b = input()
a = int(b)

c = int(math.sqrt(a))

for i in range(1000):
    d = a / (c + i)
    if d.is_integer() == True:
        break

e = d + c + i - 2
print(int(e))

Submission status: Wrong Answer

Solution code:
import math
b = input()
a = int(b)

c = int(math.sqrt(a))

for i in range(1000):
    d = a / (c + i)
    if d.is_integer() == True:
        break

e = c + i

print(d + e - 2)

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
c=N+1
n=math.sqrt(N)
n=n//1
n=int(n)
for i in range(1,n):
    if N%i==0:
        a=i
        b=N//i
        if c>a+b:
            c=a+b
print(c-2)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
m = int(math.sqrt(n))
for i in reversed(range(1, m+1)):
  print(i)
  if n % i == 0:
    j =  n // i
    print(i+j-2)
    break

Submission status: Wrong Answer

Solution code:
n = int(input())
data = []
N = n
count = 2

def pi(lis):
  ans = 1
  for i in range(len(lis)):
    ans =ans * lis[i]
  return ans


while count <= int(N**(1/2)+4):
  if n % count == 0:
    n = n / count
    data.append(count)
    continue
  else:
    count += 1
#print(n,count,int(N**(1/2) + 5),'n,count')
if (count == int(N**(1/2) + 5)) and n != 0:
    data.append(n)
      
#print(data)
sum_data = []
if len(data) == 1:
  print(int(data[0])-1)
  exit()
if len(data) == 2:
  print(int(data[0] + data[1])-2)
  exit()
for i in range(1,len(data)):
  sum_data.append(pi(data[:i]) + pi(data[i:])-2)


#print(sum_data,'sum_data')
#print(data,'data')
#print(pi([2,5,5,1]))
print(int(min(sum_data)))

Submission status: Wrong Answer

Solution code:
from math import sqrt

N = int(input())

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
num = int(input())
arr = []
temp = num
x,y = 1,1
for i in range(2, int(-(-num**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(M)
arr.sort(reverse=True)
for i in arr:
    if x*i < y*i:
        x *= i
    else:
        y *= i
print(x+y-2)

Submission status: Wrong Answer

Solution code:
num = int(input())
arr = []
temp = num
x,y = 1,1
for i in range(2, int(-(-num**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(M)


for i in arr:
    if x*i < y*i:
        x *= i
    else:
        y *= i
print(x+y-2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

if N == 2:
  print(1)
  exit();

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0 and i != n // i:
            divisors.append(i+n//i)
            
    return divisors
  
print(min(make_divisors(N))-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 and i != n // i:
            divisors.append(i+n//i)

    return divisors
  
print(min(make_divisors(N))-2)

Submission status: Wrong Answer

Solution code:
n = int(input())
data = []
N = n
count = 2

def pi(lis):
  ans = 1
  for i in range(len(lis)):
    ans =ans * lis[i]
  return ans


while count <= int(N**(1/2)+4):
  if n % count == 0:
    n = n / count
    data.append(count)
    continue
  else:
    count += 1
  if count == int(N**(1/2)) and n != 0:
    data.append(n)
    
#print(data)
sum_data = []
if len(data) == 1:
  print(int(data[0])-1)
  exit()
if len(data) == 2:
  print(int(data[0] + data[1])-2)
  exit()
for i in range(1,len(data)-1):
  sum_data.append(pi(data[:i]) + pi(data[i:])-2)


#print(sum_data)

#print(pi([2,5,5,1]))
print(int(min(sum_data)))

Submission status: Wrong Answer

Solution code:
n = int(input())
data = []
N = n
count = 2

def pi(lis):
  ans = 1
  for i in range(len(lis)):
    ans =ans * lis[i]
  return ans


while count <= int(N**(1/2)+1):
  if n % count == 0:
    n = n / count
    data.append(count)
    continue
  else:
    count += 1
  if count == int(N**(1/2)) and n != 0:
    data.append(n)
    
#print(data)
sum_data = []
if len(data) == 1:
  print(int(data[0])-1)
  exit()
if len(data) == 2:
  print(int(data[0] + data[1])-2)
  exit()
for i in range(1,len(data)-1):
  sum_data.append(pi(data[:i]) + pi(data[i:])-2)


#print(sum_data)

#print(pi([2,5,5,1]))
print(int(min(sum_data)))

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())
li = make_divisors(N)
min_n = 10**9
for i in range(len(li)):
    a = li[i]
    b = N//li[i]
    min_n = min(min_n,a+b-2)
if li == [1,N]:
    print(N-1)
else:
    print(min_n)

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())
li = make_divisors(N)
min_n = 10**9
for i in range(len(li)):
    a = li[i]
    b = N//li[i]
    min_n = min(min_n,a+b-2)
print(min_n)

Submission status: Wrong Answer

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

N = int(input())
li = prime_factor(N)
a = 1
b = N
min_n = N-1

for i in range(len(li)):
    min_n = min((a-1)+(b-1),min_n)
    a *= li[i]
    b //= li[i]
print(min_n)

Submission status: Wrong Answer

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

N = int(input())
a = b = 1
li = prime_factor(N)
li.sort()
for i in range(len(li)):
    if (a<b):
        a *= li[i]
    else:
        b *= li[i]
print((a-1)+(b-1))

Submission status: Wrong Answer

Solution code:
from math import sqrt, ceil

N = int(input())

minSteps = N - 1
for i in range(1, int(ceil(sqrt(N)))):
    if N % i == 0:
        y = N // i
        minSteps = min(minSteps, i - 1 + y - 1)

print(minSteps)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
a=n
a=math.ceil(math.sqrt(n))
for i in range(1,a):
    if n%i==0 and n%i<a:
        a=i+n/i-2
print(int(a))

Submission status: Wrong Answer

Solution code:
inf = float('inf')
N = int(input())

from math import floor
# 約数全列挙(ソート済み)
# n = 24 -> [1,2,3,4,6,8,12,24]
def divisor(n):
    left = [1]
    right = [n]
    sup = floor(pow(n,1/2))
    for p in range(2,sup+1):
        if n % p == 0:
            if p == n//p:
                left.append(p)
                continue
            left.append(p)
            right.append(n//p)
    return left, right

ans = inf
left, right = divisor(N)
for i, j in zip(left, right):
    d = abs(i-1) + abs(j-1)
    ans = min(ans, d)

print(ans)

Submission status: Wrong Answer

Solution code:
import math
min = 1000000000000

n = int(input())
for i in range(1, math.ceil(math.sqrt(n))):
    x = n / i
    if x.is_integer():
        ans = (x-1) + (i-1)
        if ans < min:
            min = ans

print(int(ans))

Submission status: Wrong Answer

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