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_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n = int(n/i)
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

l = prime_decomposition(n)
l.append(1)
l.sort()
l.reverse()
a = 1
b = 1

for i in range(len(l)):
    if a <= b:
        a *= l[len(l)-1-i]
    else:
        b *= l[len(l)-1-i]

print(a+b-2)

Submission status: Wrong Answer

Solution code:
n = int(input())

def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n = int(n/i)
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

l = prime_decomposition(n)
l.append(1)
l.reverse()
a = 1
b = 1

for i in range(len(l)):
    if a <= b:
        a *= l[len(l)-1-i]
    else:
        b *= l[len(l)-1-i]

print(a+b-2)

Submission status: Wrong Answer

Solution code:
n = int(input())

def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n = int(n/i)
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

l = prime_decomposition(n)
l.append(1)
l.sort()
a = 1
b = 1
s = len(l)//2

for i in range(len(l)):
    if a <= b:
        a *= l[i]
    else:
        b *= l[i]

print(a+b-2)

Submission status: Wrong Answer

Solution code:
n = int(input())

def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n = int(n/i)
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

l = prime_decomposition(n)
l.append(1)
l.sort()
a = 1
b = 1
s = len(l)//2

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

Submission status: Wrong Answer

Solution code:
from math import sqrt
from math import floor
n = int(input())
for i in range(2, floor(sqrt(n)) + 1):
    if n % i == 0:
        min_div = i
        break
else:
    min_div = n
ans = min_div + int(n / min_div) - 2
print(ans)

Submission status: Wrong Answer

Solution code:
import math

N=int(input())
n=math.ceil(math.sqrt(N))

ans=1000000000000

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

print(ans-2)

Submission status: Wrong Answer

Solution code:
import math

N=int(input())
n=math.ceil(math.sqrt(N))

ans=1000000000000

for i in range(1,n+1):
    if N%i==0:
        if ans>i+(N/i):
            ans=i+(N/i)
            print(i,N/i,ans)

print(ans-2)

Submission status: Wrong Answer

Solution code:
a = int(input())
s = int(a ** 0.5)
for i in range(s):
  if a%(s-i)==0:
    print(a/(s-i) + (s-i) - 2)
    break

Submission status: Wrong Answer

Solution code:
import math

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

n=factorization(N)

#print(n)
x=1
y=1
for i in reversed(range(len(n))) :
    for j in range(n[i][1]):
        if x<y:
            x*=n[i][0]
        else:
            y*=n[i][0]
    #print(x,y)
#print(x,y)

print(x+y-2)

Submission status: Wrong Answer

Solution code:
import math

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

n=factorization(N)

print(n)
x=1
y=1
for i in reversed(range(len(n))) :
    for j in range(n[i][1]):
        if x<y:
            x*=n[i][0]
        else:
            y*=n[i][0]
    print(x,y)
print(x,y)

print(x+y-2)

Submission status: Wrong Answer

Solution code:
import math

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

n=factorization(N)

x=1
y=1
for i in range(len(n)) :
    for j in range(n[i][1]):
        if x<y:
            x*=n[i][0]
        else:
            y*=n[i][0]
    #print(x,y)
#print(x,y)

print(x+y-2)

Submission status: Wrong Answer

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

min_count = 1 + input_num
for i in range(sqrt_num + 1, 1, -1):
  if(input_num % i == 0) and (min_count >= input_num//i + i):
    min_count = input_num//i + i
print(min_count)

Submission status: Wrong Answer

Solution code:
input_num = int(input())

min_count = 1 + input_num
for i in range(input_num//2 + 1, 1, -1):
  if(input_num % i == 0) and (min_count >= input_num//i + i):
    min_count = input_num//i + i
print(min_count)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

b=n
a=[]
N=math.sqrt(n)

for i in range(1,n+1):
  q, mod=divmod(n,i)
  if(mod==0):
   a=q+i
   if(a<b):
     b=a
 
print (b-2)

Submission status: Wrong Answer

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

b=n
a=[]

for i in range(1,n+1):
  q, mod=divmod(n,i)
  if(mod==0):
   a=q+i
   if(a<b):
     b=a
 
print (b-2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
ans = float('inf')
for i in range(10^6):
  if n%(i+1) == 0:
    j = n/(i+1)
    ans = min(ans, (i+1)+j-2)
print(int(ans))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
ans = float('inf')
for i in range(10^6):
  if n%(i+1) == 0:
    j = n/(i+1)
    ans = min(ans, (i+1)+j-2)
print(ans)

Submission status: Wrong Answer

Solution code:
from functools import reduce

def solve():
    N = int(input())
    primes = [1]
    primes += sorted(prime_factorize(N))
    primes += [1]

    min_sub = float('inf')
    for border in range(1, len(primes)):
        a = reduce(lambda x, y: x*y, primes[:border])
        b = reduce(lambda x, y: x*y, primes[border:])
        
        if min_sub > a + b:
            min_sub = a + b 
    
    print(min_sub-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                

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
from functools import reduce

def solve():
    N = int(input())
    primes = [1]
    primes += prime_factorize(N)
    primes += [1]

    min_sub = float('inf')
    for border in range(1, len(primes)):
        a = reduce(lambda x, y: x*y, primes[:border])
        b = reduce(lambda x, y: x*y, primes[border:])
        
        if min_sub > a + b:
            min_sub = a + b 
    
    print(min_sub-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                

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
from functools import reduce

def solve():
    N = int(input())
    primes = [1]
    primes += prime_factorize(N)
    primes += [1]

    min_sub = float('inf')
    idx = -1
    for border in range(1, len(primes)):
        a = reduce(lambda x, y: x*y, primes[:border])
        b = reduce(lambda x, y: x*y, primes[border:])
        
        if min_sub > abs(a - b):
            idx = border
            min_sub = abs(a-b)
    
    a = reduce(lambda x, y: x*y, primes[:idx])
    b = reduce(lambda x, y: x*y, primes[idx:])
    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                

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
def devide2two(n):
    arr=[]
    arr.append((n-1))
    for i in range(2, int(-(-n**0.5//1))+1):
        if n%i==0:
            a = n/i
            arr.append(i-1+ a-1)
    
    return min(arr)
n = int(input())
print(devide2two(n))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
------------------------
author : iiou16
time : 11/01/12:15
------------------------
'''


def main():
    N = int(input())
    org = N
    i = 2
    table = []
    while i * i <= N:
        while N % i == 0:
            j = org / i
            N /= i
            table.append(i + j - 2)
        i += 1
    table.append(org - 1)
    print(int(min(table)))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

q=list()

for i in range(1,n):
  if n%i==0:
    q.append(i+n/i)
    
  else:
    pass
  
q.sort()
print(q[0]-2)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
a = math.ceil(math.sqrt(n))
min_ans = float('inf')

for i in range(1, a):
    if n % i == 0:
        min_ans = min(min_ans, i+n//i-2)
print(min_ans)

Submission status: Wrong Answer

Solution code:
import math
import sys

N = int(input())

a = sys.maxsize

for i in range(1,int(math.sqrt(N))):
  if N % i == 0 and (i + int(N/i) - 2) < a:
    a = i + int(N/i) - 2

print(a)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-

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

    # 約数のペア(a,b)で、a+bが最小となるものが答え
    ans = float("inf")
    for i in range(1, N):
        if i > N**(1/2):
            break

        if N%i == 0:
            ans = min(ans, (i-1)+(N%i-1))
    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
N = int(input())
n = round(N ** 1/2)
i = n
m = 0
while m == 0:
    if N%i == 0:
        m = N/i
    else:
        i -=1
print(round(i+m-2))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
ans = float('inf')
for i in range(1,10**6)[::-1]:
    if n%i == 0:
        ans = min(ans,i + n//i - 2)

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
distance=n
count=0
for i in range(1,n//2+1):
    if n%i==0:
        j=n/i
        if distance>=i+j-2:
            distance=i+j-2
        else:
            count=1
            print(distance//1)
            break


if count==0:
    print(distance//1)

Submission status: Wrong Answer

Solution code:
n=int(input())
distance=n
count=1
for i in range(1,n//2+1):
    if n%i==0:
        j=n/i
        if distance>=i+j-2:
            distance=i+j-2
        else:
            count=1
            print(distance//1)
            break


if count==0:
    print(distance//1)

Submission status: Wrong Answer

Solution code:
n=int(input())
distance=n
count=1
for i in range(1,n//2+1):
    if n%i==0:
        j=n/i
        if distance>=i+j-2:
            distance=i+j-2
        else:
            count=1
            print(distance)
            break


if count==0:
    print(distance)

Submission status: Wrong Answer

Solution code:
N=int(input())

li=[]
l=0
m=0

for i in range(N):
  if N%(i+1)==0:
    l=i
    m=N/(i+1)-1
    li.append(l+m)
    l=0
    m=0
  else:
    pass

print(min(li))

Submission status: Wrong Answer

Solution code:
N=int(input())

li=[]
l=0
m=0

for i in range(N):
  if N%(i+1)==0:
    l=i+1
    m=N/(i+1)
    li.append(l+m-1)
    l=0
    m=0
  else:
    pass

print(min(li))

Submission status: Wrong Answer

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

ans = n - 1

for a in range(2, m):
  if n % a == 0:
    ans = min(ans, a + n//a - 2)
    
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math


def main():
    a = int(input())
    for i in range(int(math.sqrt(a)) + 1, 0, -1):
        if(a % i == 0):
            print(i + (a / i) - 2)
            return


if(__name__ == "__main__"):
    main()

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

ans = n-1

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

Submission status: Wrong Answer

Solution code:
import sys
 
input = sys.stdin.readline()
N = int(input)
sum = N
if N % 2 == 0:
  halfN = N/2
else:
  halfN = N+1/2

for x in range(2,int(halfN)):
  if N%x==0 and (N/x+x-2)<N:
    sum = N/x + x - 2
print(int(sum))

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

l = make_divisors(n)
ans = n
for i in range(len(l)):
  for j in range(len(l)):
    if n == l[i] * l[j]:
      ans = min(ans,l[i]+l[j])
print(ans - 2)

Submission status: Wrong Answer

Solution code:
import math
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())


N=II()
res=INTMAX
for i in range(1,math.floor(math.sqrt(N))):
    if N % i == 0:
        res = min(res, i + (N // i) - 2)
print(res)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
ans=n
i=1
while(i<math.sqrt(n)):
    if n%i==0:
        d=i+n/i-2
        ans=min(ans,d)
    i+=1
print(int(ans))

Submission status: Wrong Answer

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

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

l=factorize(n)
print(l)
if len(l)==1:
    print(n-1)
    exit()

if len(l)==2:
    print(l[0]+l[1]-2)
    exit()

while True:
    l.sort(reverse=True)
    temp=l[-1]*l[-2]
    #print("temp:",l)
    l.pop()
    l.pop()
    #print("pop: ",l)
    l.append(temp)
    #print("app: ",l)
    if len(l)==2:
        break
#print(l)
print(l[0]+l[1]-2)

Submission status: Wrong Answer

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

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

l=factorize(n)

if len(l)==1:
    print(n-1)
    exit()

if len(l)==2:
    print(l[0]+l[1]-2)
    exit()

while True:
    l.sort(reverse=True)
    temp=l[-1]*l[-2]
    l.pop()
    l.pop()
    l.append(temp)
    if len(l)==2:
        break

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

Submission status: Wrong Answer

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

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

l=factorize(n)

if len(l)==1:
    print(l[0]-1)
    exit()

if len(l)==2:
    print(l[0]+l[1]-2)
    exit()

while True:
    l.sort(reverse=True)
    temp=l[-1]*l[-2]
    l.pop()
    l.pop()
    l.append(temp)
    if len(l)==2:
        break

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

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
startnum = math.floor(math.sqrt(n))
for i in range(startnum,0,-1):
	if n % i == 0:
		print(i + (n//i) - 1)
		exit()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
N = int(n * 0.5)
while n % N != 0:
    N -= 1
print(n//N + N - 2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from itertools import chain
import numpy as np


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

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

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

    return arr


N = int(input())

ans = None

if float.is_integer(N**0.5):
    ans = int((N**0.5) * 2 - 2)
else:
    factors = list(
        chain.from_iterable([[x[0]] * x[1] for x in factorization(N)])
    )

    if len(factors) == 1:
        ans = factors[0] - 1
    else:
        for i in range(1, len(factors)):
            print(factors[:i], factors[i:])
            dist = np.prod(factors[:i]) + np.prod(factors[i:]) - 2
            if ans is None:
                ans = dist
            elif dist < ans:
                ans = dist

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import chain
import numpy as np

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


factors = list(chain.from_iterable([[x[0]] * x[1] for x in factorization(N)]))
ans = None

if len(factors) == 1:
    ans = factors[0] - 1
else:
    for i in range(1, len(factors)):
        dist = np.prod(factors[:i]) + np.prod(factors[i:]) - 2
        if ans is None:
            ans = dist
        elif dist < ans:
            ans = dist

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math 
n = int(input())
s = math.sqrt(n)
ps = math.floor(s)
for i in range(1,ps+1):
    for j in range(ps,ps*2+1):
        if i*j == n:
            print(i+(j-2))
            break

Submission status: Wrong Answer

Solution code:
import math 
n = int(input())
s = math.sqrt(n)
nextN = math.floor(s)
if nextN*nextN == n:
    print((nextN*2)-2)
else:
    print((nextN*2)-1)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
ans = n
nn = math.floor(n**0.5)
for a in range(1,nn):
    if n%a == 0:
        ans = min(ans,a+n//a-2)
    else:
        pass
print(ans)

Submission status: Wrong Answer

Solution code:
import math


n = int(input())
ans = n
nn = math.ceil(n**0.5)

for a in range(1,nn):
    if n%a == 0:
        ans = min(ans,a+n//a-2)
    else:
        pass
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
N=int(input())    
NS=math.floor(N**0.5)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
 
mi = 10**10

for a in range(1, int(math.sqrt(N)), 1):
  if N % a == 0:
    b = N//a
    if mi > a+b-2:
      mi = a+b-2
print(mi)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
 
mi = 10**10

for a in range(1, int(math.sqrt(N))+1, 1):
  if N % a == 0:
    b = N//a
    if mi > a+b-2:
      mi = a+b-2
print(mi)

Submission status: Wrong Answer

Solution code:
N = int(input())
 
mi = 10**10
 
for a in range(N):
  for b in range(a):
    if a*b == N:
      if mi < a*b-2:
        mi == a*b-2
print(mi)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(range(2,int(n**0.5//1+1)))
ans=10**11
count=0
for i in l:
    if n%i==0:
        a=i+int(n/i)-2
        ans=min(ans,a)
        count+=1
print(ans if count>0 else n-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(range(2,int(n**0.5//1)))
ans=10**11
count=0
for i in l:
    if n%i==0:
        a=i+int(n/i)-2
        ans=min(ans,a)
        count+=1
print(ans if count>0 else n-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(range(2,int(n**0.5//1)))
ans=10**9
count=0
for i in l:
    if n%i==0:
        a=i+int(n/i)-2
        ans=min(ans,a)
        count+=1
print(ans if count>0 else n-1)

Submission status: Wrong Answer

Solution code:
import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

# input = sys.stdin.readline


def main():
    N = int(input())
    min_s = 10 ** 12

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

    print(int(min_s - 2))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

# input = sys.stdin.readline


def main():
    N = int(input())
    min_s = 10 ** 12

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

    print(min_s - 2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
sq = int(math.sqrt(N))
if sq**2 == N:
    print(2*N-2)
else:
    for i in range(sq):
        j=sq-i
        if not N%j:
            print(j+N//j-2)
            break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math


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

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#start 1,1

n = int(input())

mina = n
for a in range(1,int(n**2)+1):
    if n%a ==0:
        mina = min(n/a+a,mina)

print(int(mina-2))

Submission status: Wrong Answer

Solution code:
#start 1,1

n = int(input())

mina = n
for a in range(1,n//2+1):
    if n%a ==0:
        mina = min(n/a+a,mina)

print(int(mina-2))

Submission status: Wrong Answer

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

n = long(raw_input())
fct = factorize(n)
if len(fct)==1:
  fct.append(1)
ans = [1,1]
for i in range(0,len(fct)):
  if len(fct)>2:
    fct_min = fct.pop(fct.index(min(fct)))
    fct_second_min = fct.pop(fct.index(min(fct)))
    tmp = fct_min * fct_second_min
    fct.append(tmp)
  else:
    break
print fct[0]+fct[1]-2

Submission status: Wrong Answer

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

n = long(raw_input())
fct = factorize(n)
if len(fct)==1:
  fct.append(1)
ans = [1,1]
for i in range(0,len(fct)):
  print fct
  if len(fct)>2:
    fct_min = fct.pop(fct.index(min(fct)))
    fct_second_min = fct.pop(fct.index(min(fct)))
    tmp = fct_min * fct_second_min
    fct.append(tmp)
  else:
    break
print fct[0]+fct[1]-2

Submission status: Wrong Answer

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

n = long(raw_input())
fct = factorize(n)
ans = [1,1]
for i in range(0,len(fct)):
  ans_index = ans.index(min(ans))
  ans[ans_index] = ans[ans_index]*fct[i]
print ans[0]+ans[1]-2

Submission status: Wrong Answer

Solution code:
import math
n = int(input());
s = n - 1
for i in range(1,int(math.sqrt(n))):
    t = n / i
    if t.is_integer() == True and s > (t-1)+(i-1):
        s = (t-1)+(i-1)
print(int(s))