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:
# 2020/01/23
# AtCoder Beginner Contest 144 - C

# Input
n = int(input())

nsq = int(n ** (1/2)) + 1

x = nsq
y = nsq

while x >= 1:
    wkn = x * y
    if n == wkn:
        ans = (x - 1) + (y - 1)
        break
    elif n > wkn:
        y = y + 1
    else:
        x = x - 1

# Output
print(ans)

Submission status: Wrong Answer

Solution code:
# 2020/01/23
# AtCoder Beginner Contest 144 - C

# Input
n = int(input())

nsq = int(n ** (1/2)) + 1

x = nsq
y = nsq

while x >= 1:
    print(x, y)
    wkn = x * y
    if n == wkn:
        ans = (x - 1) + (y - 1)
        break
    elif n > wkn:
        y = y + 1
    else:
        x = x - 1

# Output
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())
hoge=prime_factorize(n)
hoge.sort()
hoge.reverse()
a=1
b=1
for i in hoge:
  if a>b:
    b*=i
  else:
    a*=i
print((a-1)+(b-1))

Submission status: Wrong Answer

Solution code:
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
  
n=int(input())
hoge=prime_factorize(n)
hoge.sort()
hoge.reverse()
a=1
b=1
for i in hoge:
  if a>b:
    b*=i
  else:
    a*=i
print((a-1)*(b-1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
bar=10**12
d=[]
for i in range(1,int(N**0.5)+1):
  if N%i==0 and i!=N//i and i+N//i<bar:
    d.append(i+N//i)
    bar=i+N//i
#print(d)
print(min(d)-2)

Submission status: Wrong Answer

Solution code:
n=int(input())


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

Submission status: Wrong Answer

Solution code:

import sys
import heapq
import math

INF = float("inf")


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

    for i in range(1, 10**6):
        if N % i == 0:
            ans = min(ans, (i - 1) + (N // i - 1))

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

N = int(input())
factN = prime_factorize(N)
A = 1
B = 0
if len(factN) > 1:
    for i, j in enumerate(factN):
        if i != len(factN) - 1:
            A *= j
        else:
            B = j
else:
    A = factN[0]
print(A + B - 2 if B != 0 else A + B - 1)

Submission status: Wrong Answer

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

    count = n + 1

    for i in range(1,int(n**0.5)):
        if n % i == 0 and n // i + i < count:
            count = n // i + i

    print(count-2)

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)

    return divisors

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

    count = n + 1

    ls = make_divisors(n)

    if len(ls) == 2:
        print(count-2)
        exit()

    for i in range(len(ls)):
        if n // ls[i] + ls[i] < count:
            count = n // i + i

    print(count-2)

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)

    return divisors

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

    count = n + 1

    ls = make_divisors(n)

    for i in range(len(ls)):
        if n // ls[i] + ls[i] < count:
            count = n // i + i

    print(count-2)

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)

    return divisors

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

    count = n + 1

    ls = make_divisors(n)

    for i in range(len(ls)-1):
        if i % 2 != 0:
            continue
        if ls[i] + ls[i+1] < count:
            count = ls[i] + ls[i+1]

    print(count-2)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans = float("inf")
for i in range(1, int(math.sqrt(n))):
    if n%i == 0:
        ans = min(ans, i-1+(n//i)-1)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
B = int(pow(N, 0.5))

tmp = pow(10, 12)
for b in range(1, B):
    if N % b == 0:
        a = N // b
        if tmp > a + b - 2:
            tmp = a + b - 2

print(tmp)

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = N
for i in range(1, int(N**0.5)):
    j, m = divmod(N, i)
    if m != 0:
        continue
    ans = min(ans, i + j - 2)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
root = int(math.sqrt(n))
ans = 0
flag = 0
for i in range(root, 10**6+1):
    if n % i == 0:
        flag = 1
        ans = min(int((n/i)) + i - 2, ans)
        break
if flag==1: pass
else: # nが素数
  ans = n + 1 - 2
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
root = int(math.sqrt(n))
ans = 0
flag = 0
for i in range(root, 10**6+1):
    if n % i == 0:
        flag = 1
        #print('i='.format(i))
        ans = int((n/i)) + i - 2
        break
if flag==1: pass
else: # nが素数
  ans = n + 1 - 2
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
root = int(math.sqrt(n))
ans = 0
flag = 0
for i in range(root, 10**6+1):
    if n % i == 0:
        flag = 1
        print('i='.format(i))
        ans = int((n/i)) + i - 2
        break
if flag==1: pass
else: # nが素数
  ans = n + 1 - 2
print(ans)

Submission status: Wrong Answer

Solution code:
import math
 
N = int(input())
 
min_cand = 10**9
 
for i in range(1,(int(math.sqrt(N))+1)):
  if N % i == 0 and min_cand > (i + (N // i)):
    min_cand = (i + (N // i))
    
print(min_cand - 2)

Submission status: Wrong Answer

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

ans = 10 ** 13
for i in range(1, int(sqrt(N))):
    if N % i == 0:
        ans = min(ans, i + N // i - 2)
print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
  n = int(input())
  result = 0
  
  for i in range(int(n ** 0.5) + 1, 0, -1):
    j = 1
    r = i * j
    
    while r <= n:
      if i == 1:
      	print(r)
      j += 1
      r = i * j
      
      if r == n:
        return i + j - 2
  


print(solve())

Submission status: Wrong Answer

Solution code:
def solve():
  n = int(input())
  act = 1
  result = 0
  
  while True:
    if act == n:
      return act
    
    _max = act ** 2
    _min = act
    if n > _min and n <= _max:
      _act = 1
      
      while act * _act < _max:
        _act += 1
        
        if _act * act == n:
          return act + _act - 2
    
    act += 1

print(solve())

Submission status: Wrong Answer

Solution code:
def solve():
  n = int(input())
  act = 1
  result = 0
  
  while True:
    if act == n:
      return act
    
    _max = act ** 2
    _min = (act - 1) ** 2
    if n > _min and n <= _max:
      _act = 1
      
      while act * _act < _max:
        _act += 1
        
        if _act * act == n:
          return act + _act - 2
    
    act += 1

print(solve())

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    a = 0
    b = 0

    M = int(N**(1/2))
    for i in range(1, M):
        if N%i == 0:
            a = i
            b = (N//i)
    print(a + b - 2)
    return 0
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import itertools
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())

    a = prime_factorize(N)
    if len(a) < 2:
        print(a[0]-1)
    elif len(a) == 2:
        print(sum(a) - 2)
    else:
        while len(a) > 2:
            tmp_1 = a.pop(0)
            tmp_2 = a.pop(1)
            a.insert(0, tmp_1*tmp_2)
        print(sum(a) - 2)
    return 0
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import sqrt, ceil


def main():
    N = int(input())
    lst = []
    for a in range(1, ceil(sqrt(N)))[::-1]:
        if N % a == 0:
            b = N // a
            lst.append(a + b - 2)

    print(min(lst))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import sqrt, ceil

def main():
    N = int(input())
    for a in range(1, ceil(sqrt(N)))[::-1]:
        if N % a == 0:
            b = N // a
            print(a + b - 2)
            return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

mx = math.ceil(n ** 0.5)

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

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 = make_divisors(N)
if len(div) % 2 == 0:
	ind_2 = len(div) // 2
	ind_1 = ind_2 - 1
	print(div[ind_1] + div[ind_2])
else:
	ind = len(div) // 2
	print(div[ind] * 2)

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))


N = int(input())
ans = 10 ** 12
for i in range(1, math.ceil(N**0.5)+1):
    if N / i == N // i:
        print(i, N // i)
        ans = min(ans, i + N // i - 2)
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)
        divisors.sort()
  return divisors
l = make_divisors(N)
x = l[len(l) // 2 - 1]
y = l[len(l) // 2]
print(x + y -2)

Submission status: Wrong Answer

Solution code:
N = int(input())
X=10**12
Y=10**12
flag = 0
for i in range(2,int(N**0.5)):
  if N%i==0:
    flag = 1
    temp = N//i
    if X+Y > temp+i:
      X = i
      Y = temp
      
if flag==0 or X+Y > N+1:
  X = N
  Y = 1
print(X+Y-2)

Submission status: Wrong Answer

Solution code:
N = int(input())
X=10**12
Y=10**12
flag = 0
for i in range(2,int(N**0.5)):
  if N%i==0:
    flag = 1
    temp = N//i
    if X+Y > temp+i:
      X = i
      Y = temp
      
if flag==0:
  X = N
  Y = 1
print(X+Y-2)

Submission status: Wrong Answer

Solution code:
n = int(input())
if n == 2:
    print(1)
    exit()
if n == 3:
    print(2)
    exit()
a = n** 0.5
if n%a == 0:
    print(int(2*a)-2)
else:
    while n%a != 0:
        a = a//1-1 
        if n%a == 0:
            print(int(a + n//a-2))
            exit()

Submission status: Wrong Answer

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

n = int(input())
factor = factorize(n)

ans = int(1e13)
for fa in factor:
    a, b = fa
    ans = min(ans, a + b - 2)
print(ans)

Submission status: Wrong Answer

Solution code:
from functools import reduce

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())
factor = [1] + prime_factorize(n)

ans = int(1e13)
for i in range(1,len(factor)):
    a = reduce(lambda x,y:x*y, factor[:i])
    b = reduce(lambda x,y:x*y, factor[i:])
    ans = min(ans, a + b - 2)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
def ii():
  return int(input())

N = ii()

def facts(n):
  facts = []
  for i in range(1, int(math.sqrt(n))+1):
    if n%i==0:
      facts.append(i)
  return facts

fs = facts(N)
print(fs)
a = fs[-1]
b = N//a

print(a+b-2)

Submission status: Wrong Answer

Solution code:
from math import ceil


def main():
    N = int(input())
    i = 2
    is_prime_number = True
    while i ** 2 <= N:
        if N % i == 0:
            is_prime_number = False
            break
        i += 1
    if is_prime_number:
        print(N - 1)
    else:
        print(ceil(2 * (N ** 0.5) - 2))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=[]
if n==1:
    print(1)
else:
    for i in range(1,10**6):
        if i>=n:
            break
        elif n%i==0:
            ans.append(i+(n//i))
    print(min(ans)-2)

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=[]
for i in range(1,10**6):
    if i>=n:
        break
    elif n%i==0:
        ans.append(i+(n//i))
print(min(ans)-2)

Submission status: Wrong Answer

Solution code:
import math
def ints():
  return [int(x) for x in input().split()]
def ii():
  return int(input())

N = ii()

def facts(n):
  facts = []
  for i in range(1, int(math.sqrt(n))+1):
    if n%i==0:
      n //= i
      facts.append(i)
  return facts

a = facts(N)[-1]
b = N//a

print(a+b-2)

Submission status: Wrong Answer

Solution code:
n = int(input())

ans_min = n - 2
for a in range(1, int(n ** 0.5) + 1):
    b = n / a
    if b.is_integer():
        if a + b - 2 < ans_min:
            ans_min = a + b - 2
print(ans_min)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools


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

    return N,


def solve(N, ):
    move = 1000000000000
    for i in range(9):
        a = i + 1

        b = N // a

        if a * b == N:

            move = min(move, a - 1 + b - 1)


        else:
            continue

    return move


if __name__ == '__main__':
    input = read()
    print(solve(*input))

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np

def main():
    N = int(input())
    lp = prime_factorize(N)
    ans = N - 1
    laa = []

    for j in range(len(lp)//2):
        l = list(itertools.combinations(lp,j+1))
        la = list(set(l))
        la = list(map(np.prod, la))
        laa += la

    laa.sort()
    laa = laa[:-1]
    #print(laa)

    for i in range(len(laa)):

        a = laa[i]
        b = N // a                
        #print(a, b)
        if (a != 1) and (b != 1):
            buf = a + b - 2
        else:
            buf = a + b - 1
        if ans > buf:
            ans = buf

    print(ans)

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__":
    main()

Submission status: Wrong Answer

Solution code:
#import itertools
import numpy as np

def main():
    N = int(input())
    l = prime_factorize(N)
    #print(l)
    #print(np.prod(l))#総乗

    #p_list = list(itertools.permutations(l))
    #print(p_list)
    ans = N - 1
    
    for i in range(len(l)-1):
        #print(l[:i+1], l[i+1:])
        a = np.prod(l[:i+1])
        b = np.prod(l[i+1:])
            
        #print(a, b)
        if (a != 1) and (b != 1):
            buf = a + b - 2
        else:
            buf = a + b - 1
        if ans > buf:
            ans = buf
    print(ans)

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__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    l = prime_factorize(N)
    ans = N - 1
    for i in l:
        a = i
        b = N // i
        #print(a, b)
        if (a != 1) and (b != 1):
            buf = a + b - 2
        else:
            buf = a + b - 1
        if ans > buf:
            ans = buf
    print(ans)

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__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    a = prime_factorize(N)
    ans = N - 1
    for i in a:
        #print(i, N//i)
        if ans > (i + (N // i)):
            if i != 1 and (N // i) != 1:
                ans = i + (N // i) - 2
            elif i == 1 and (N // i) == 1:
                ans = 2
            else:
                ans = i + (N // i) - 1
    print(ans)

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__":
    main()

Submission status: Wrong Answer

Solution code:
from math import sqrt
n = int(input())
m = 2*n

for i in range(1, int(sqrt(n))):
    if n % i == 0:
        a = n // i
        b = n // a
        if a+b <= m:
            m = a+b

print(m-2)

Submission status: Wrong Answer

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

solve()

Submission status: Wrong Answer

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

solve()

Submission status: Wrong Answer

Solution code:
N = int(input())

min = float('inf')

times = int(N**0.5)

for i in range(1, times, 1):

    if N%i==0:
        j = N//i
    else:
        continue
    temp = i+j-2
    if min > temp:
        min = temp

print(min)

Submission status: Wrong Answer

Solution code:
N = int(input())

flag = True

for i in range(1,10):
    for j in range(1,10):
        #print(i, j)
        if i * j == N:
            print("Yes")
            flag = False
    if not(flag):
        break

if flag:
    print("No")

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
r = list()
for a in range(1,int(math.sqrt(10**12))):
    if n % a == 0:
        b = n//a
        r.append(a+b-2)
print(min(r))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
r = list()
for a in range(1,int(math.sqrt(10**12))):
    if n % a == 0:
        b = n/a
        r.append(a+b-2)
print(int(min(r)))

Submission status: Wrong Answer

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

inp = int(input())
a = 1
b = 1
yn = prime_decomposition(inp)
for pon in range(0,-(-len(yn)//2)+1,2):
  try:
    a *= yn[pon]
  except:
    pass

  try:
    b *= yn[pon+1]
  except:
    pass

print(int(a+b-2))

Submission status: Wrong Answer

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

inp = int(input())
a = 1
b = 1
yn = prime_decomposition(inp)
for pon in range(0,-(-len(yn)//2)+1,2):
  try:
    a *= yn[pon]
  except:
    pass

  try:
    b *= yn[pon+1]
  except:
    pass

print(a+b-2)

Submission status: Wrong Answer

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

inp = int(input())
a = 1
b = 1
yn = prime_decomposition(inp)
for pon in range(0,-(-len(yn)//2)+1,2):
  try:
    a *= yn[pon]
  except:
    pass
    
  try:
    b *= yn[pon+1]
  except:
    pass

print(a+b-2)

Submission status: Wrong Answer

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

inp = int(input())
a = 1
b = 1
yn = prime_decomposition(inp)
for pon in range(0,-(-len(yn)//2)+1,2):
  a *= yn[pon]
  try:
    b *= yn[pon+1]
  except:
    pass

print(a+b-2)

Submission status: Wrong Answer

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

inp = int(input())
a = 1
b = 1
yn = prime_decomposition(inp)
for pon in range(-(-len(yn)//2)):
  a *= yn[pon]
  try:
    b *= yn[pon+1]
  except:
    pass
  pon += 1
print(a+b-2)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
ans = 1e12

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

Submission status: Wrong Answer

Solution code:
def md(n):
    d=[]
    da=d.append
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            da(i)
            if i!=n//i:da(n//i)
    d.sort()
    return d
n = int(input())
t=md(n)
u=len(t)
midopen = 0
mini = 999999999999999
if u%2==1:midopen=u//2
else:midopen=u//2+1
for i in range(midopen):
    x = t[i]
    y = n//x
    mini = min(mini,x+y-2)
print(mini)

Submission status: Wrong Answer

Solution code:
def md(n):
    d=[]
    da=d.append
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            da(i)
            if i!=n//i:da(n//i)
    d.sort()
    return d
t=md(int(input()))
u=len(t)
if u%2==1:print(t[u//2]*2,t[u//2]*2-2)
else:print(t[u//2-1]+t[u//2]-2)

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = 1000000000000

a = 1
while a * a <= n:
  if n % a != 0:
    a += 1
    continue
  b = n / a
  ans = min(ans, a + b - 2)
  a += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = 1000000000000

a = 1
while a * a <= n:
  if n % a != 0:
    a += 1
    continue
  b = n % a
  ans = min(ans, a + b - 2)
  a += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
min_result = 10**12
for n in range(1,int(N**0.5)):
    if N%n == 0:
        result = n + int(N/n) - 2
        if min_result > result:
            min_result = result
print(min_result)

Submission status: Wrong Answer

Solution code:
N = int(input())
min_result = 10**12
for n in range(1,int(N**0.5)):
    if N%n == 0:
        result = n + int(N/n) - 2
    if min_result > result:
        min_result = result
print(min_result)

Submission status: Wrong Answer

Solution code:
N = int(input())
import math
root_a = math.floor(math.sqrt(N))
a = 1
b = 1
ans = N

for i in range(a, root_a + 1):
    for j in range(b, N):
        if i*j == N:
            if (i+j-2) < ans:
                ans = i+j-2

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
li = list()
n = N
for i in range(1, N+1):
	if N % i == 0:
		li.append([i, int(N/i)])
for x in li:
	tmp = x[0] + x[1]
	if tmp <= n:
		n = tmp
ans = n - 2
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 10*18
#N<10**12より√N<10**6]
for i in range(1, 10 ** 6):
    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())
ans = 10*18
#N<10**12より√N<10**6]
for i in range(1, 10 ** 6):
    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())
a = []
b = 0
c = []
for i in range (N):
    if N % (i+1) == 0:
        a.append(i+1)
for i in a:
    b = N / i
    c.append(b+i-2)
print(min(c))

Submission status: Wrong Answer

Solution code:
n = int(input())
i = 1
while True:
  if i * i > n:
    break
  i += 1
print(n - (i - 1) ** 2 + 2*(i - 2))

Submission status: Wrong Answer

Solution code:
n = int(input())
i = 1
while True:
  if i * i > n:
    break
  i += 1
print(n - (i - 1) ** 2 + 2*(i - 1))

Submission status: Wrong Answer

Solution code:
n = int(input())
i = 1
while True:
  if i * i > n:
    break
  i += 1
print(n - (i - 1) ** 2 + i - 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

ans = float('inf')
for i in range(1, math.ceil(n**(1/2))):
    if n%i == 0:
        a = i
        b = n // i
        d = a-1 + b-1
        ans = min(ans, d)

print(ans)

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
p=math.floor(math.sqrt(N))
while N % p > 0:
    p-=1
q=N//p
print(p+q)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

n = int(input());
#n = [int(i) for i in input().split()];
#S = [str(s) for s in in_S]

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
    
m = make_divisors(n)
#print(m);

count = 0;
for i in range(0,len(m),2):
    #print(i);
    if i==len(m)-1:
        break;
    tmp =  (m[i]-1) + (m[i+1]-1);
    #print(tmp);
    if tmp < count or count == 0:
        count = tmp;
    #if n%i == 0 and n/i <= 9:
        #jud ='Yes';
print(count);

Submission status: Wrong Answer

Solution code:
N = int(input()) 

def prime_factorization(N):
    ans = [1]
    tmp = int(N**(1/2))+1
    for num in range(2, tmp):
        while N%num == 0:
            N //= num
            ans.append(num)
    
    ans.append(N)
    return ans

prime_list = sorted(prime_factorization(N))
while len(prime_list)!=2:
    tmp = prime_list[0]*prime_list[1]
    prime_list = prime_list[2:]
    prime_list.append(tmp)
    prime_list = sorted(prime_list)

print(sum(prime_list)-2)

Submission status: Wrong Answer

Solution code:
import math

def main():
    N = int(input())
    min_steps = N
    for i in range(1, math.floor(math.sqrt(N))):
        if N % i == 0:
            a, b = i, N//i
            min_steps = min(min_steps, a-1+b-1)
    print(min_steps)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

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

Submission status: Wrong Answer

Solution code:
N = int(input())
num_list = [(i-1) + (N//i-1) for i in range(1, int(N**(1//2))+1) if N%i == 0]
print(min(num_list))