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:
# C
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())
divisors = make_divisors(N)
memo = 0
maX = divisors[0] + divisors[len(divisors) - 1]
for (i, r) in zip(divisors, reversed(divisors)):
    maX = min(i + r, maX)
    memo = i
    if memo == r:
        break
print(maX)

Submission status: Wrong Answer

Solution code:
n = int(input())
data = []
N = n
count = 2
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(sum(data[:i]) + sum(data[i:])-2)

#print(sum_data)

print(int(min(sum_data)))

Submission status: Wrong Answer

Solution code:
def solve(N):
    condition=[]
    tmp_condition = N*2
    for i in range(1,N+1):
        if i in condition:
            continue
        if N%i==0:
            tmp = N/i
            condition.append(i)
            condition.append(tmp)
            if (tmp+i)<tmp_condition:
                tmp_condition = tmp+i
    else:
        return(tmp_condition-2)
if __name__ == '__main__':
    print(solve(int(input())))

Submission status: Wrong Answer

Solution code:
N=int(input())
condition=[]
tmp_condition = N*2
for i in range(1,N+1):
    if i in condition:
        continue
    if N%i==0:
        tmp = N/i
        condition.append(i)
        condition.append(tmp)
        if (tmp+i)<tmp_condition:
            tmp_condition = tmp+i
else:
    print(tmp_condition-2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

N = int(stdin.readline().rstrip())

move_i = 0
move_j = 0

result = []

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

result.sort()

index = len(result) // 2 - 1

ans = (result[index] - 1) + (result[index+1] - 1) 

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = n
b = 1
leng = a+b-2

for i in range(2, int(n**0.5)):
    if a % i == 0:
        a = a / i
        b = b * i
if leng > a+b-2:
    leng = a+b-2
        
print(int(leng))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = n
b = 1
leng = a+b-2

for i in range(2, int(n**0.5)):
    if a % i == 0:
        a = a / i
        b = b * i
leng = a+b-2
        
print(int(leng))

Submission status: Wrong Answer

Solution code:
from math import sqrt

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = n
b = 1
leng = a+b-2

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

Submission status: Wrong Answer

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

n = int(input())
a = n
b = 1
leng = a+b-2

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

Submission status: Wrong Answer

Solution code:
N = int(input())
import math 
yakusuu_list = []
for i in range (int(math.sqrt(N)),0,-1):
  if N % i == 0:
    yakusuu = i
    break
print(i+ N/i -2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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

s = prime_factorize(n)
x = 1 
y = 1 
for i in s[::-1]:
        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())

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

s = prime_factorize(n)
x = 1 
y = 1 
for i in s:
        if x * i <= y * i:
                x *= i
        else:
                y *= i   

print(x+y-2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = n - 1
for i in range(2, 10^6):
  
  if n%i==0 and i+n/i-2<ans:
    ans = int(i + n / i - 2)
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = n - 1
for i in range(2, 10^6):
  if n%i==0 and i+n/i-2<ans:
    ans = i + int(n / i) - 2
print(ans)

Submission status: Wrong Answer

Solution code:
import math
s = input().split() #標準入力　sに値を入れる
n = int(s[0])
root = int(math.sqrt(n))
ans = 10**18
for i in range(1, root):
    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
s = input().split() #標準入力　sに値を入れる
n = int(s[0])
root = int(math.sqrt(n))
ans = 10**30
for i in range(1, root):
    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
s = input().split() #標準入力　sに値を入れる
n = int(s[0])
root = int(math.sqrt(n))
ans = 10**9
for i in range(1, root):
    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())
rn = int(n**(0.5))+1
ans = n
for i in range(1,rn):
	if n%i == 0:
		ans = min(n//i+i, ans)

print(ans-2)

Submission status: Wrong Answer

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

print(ans-2)

Submission status: Wrong Answer

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

print(ans-2)

Submission status: Wrong Answer

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

    # divisors.sort()
    return divisors
n=int(input())

d=make_divisors(n)


count=0
ans=[]
for i in d:
    pair=n/i
    count=(pair-1)+(i-1)
    ans.append(count)

print(min(ans))

Submission status: Wrong Answer

Solution code:
from math import sqrt, ceil
n = int(input())

distance = 10**13
for i in range(1, ceil(sqrt(n))):
    if n % i == 0:
        new_distance = n//i + i
        if new_distance < distance:
            distance = new_distance

print(distance - 2)

Submission status: Wrong Answer

Solution code:
from math import sqrt, floor
n = int(input())

distance = 10**13
for i in range(1, floor(sqrt(n))):
    if n % i == 0:
        new_distance = n//i + i
        if new_distance < distance:
            distance = new_distance

print(distance - 2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
minn=N-1
for i in range(2,round((N-1)**0.5)):
    if N%(i+1)==0 and minn>N//(i+1)-1+i:
        minn=N//(i+1)-1+i
if minn<=(N-1):
    print(minn)
else:
    print(N-1)

Submission status: Wrong Answer

Solution code:
n = int(input())

s = int(n**0.5)
temp = n
li = [1]

for i in range(2,s+1):
    if temp%i == 0:
        while temp%i == 0:
            temp = temp/i
        li.append(i)

t = n//li[-1]

print((t-1) + (li[-1]-1))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Nov  6 21:49:38 2019

@author: over-
"""

N=int(input())

ans=N
for i in range(1,10**12):
    if i > N: break
    if N%i == 0:
        A=(N/i-1)+(i-1)
        if A < ans:
            ans = A
            
print(int(A))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Nov  6 21:49:38 2019

@author: over-
"""

N=int(input())

ans=N
for i in range(1,10**6):
    if i > N: break
    if N%i == 0:
        A=(N/i-1)+(i-1)
        if A < ans:
            ans = A
            
print(int(A))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Nov  6 21:49:38 2019

@author: over-
"""

N=int(input())

ans=N
for i in range(1,10**6):
    if i**2 >= N: break
    if N%i == 0:
        A=(N/i-1)+(i-1)
        if A < ans:
            ans = A
            
print(int(A))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Nov  6 21:49:38 2019

@author: over-
"""

N=int(input())

ans=N
for i in range(1,10**6):
    if i**2 > N: break
    if N%i == 0:
        A=(N/i-1)+(i-1)
        if A < ans:
            ans = A
            
print(int(A))

Submission status: Wrong Answer

Solution code:
tall = int(input())
bit = int(tall**(1/2))
while ((tall/bit)%1 != 0):
  bit -= 1
print(bit+tall/bit-2)

Submission status: Wrong Answer

Solution code:
def divide(x):
    result = []

    if x == 1:
        return []

    if x == 2:
        return [2]

    if x % 2 == 0:
        result.extend([2])
        result.extend(divide(int(x/2)))
        return result

    if x % 3 == 0:
        result.extend([3])
        result.extend(divide(int(x/3)))
        return result

    if x % 5 == 0:
        result.extend([5])
        result.extend(divide(int(x/5)))
        return result

    if x % 7 == 0:
        result.extend([7])
        result.extend(divide(int(x/7)))
        return result

    return [x]

def rank(arr):
    lastIndex = len(arr) - 1
    while lastIndex > 0:

        for i in range(lastIndex):
            if arr[i+1] < arr[i]:
                tmp = arr[i+1]
                arr[i+1] = arr[i]
                arr[i] = tmp

        lastIndex = lastIndex - 1

    return arr


def calculate(result):
    if len(result) == 0:
        return 0

    if len(result) == 1:
        if result[0] > 1:
            return result[0] - 1
        return result[0]

    if len(result) == 2:

        if result[0] > 1:
            result[0] = result[0] - 1

        if result[1] > 1:
            result[1] = result[1] - 1

        return result[0] + result[1]

    else:

        if len(result) % 2 == 0:
            s1 = 1
            s2 = 1
            for i in range(int(len(result) / 2)):
                if i % 2 == 0:
                    s1 *= (result[i] * result[len(result) - 1 - i])
                else:
                    s2 *= (result[i] * result[len(result) - 1 - i])
            if s1 > 1:
                s1 = s1 - 1

            if s2 > 1:
                s2 = s2 - 1
            return s1 + s2

        else:
            s1 = 1
            s2 = 1
            for i in range(int((len(result)-1) / 2)):
                if i % 2 == 0:
                    s1 *= (result[i] * result[len(result) - 1 - i])
                else:
                    s2 *= (result[i] * result[len(result) - 1 - i])

            m = result[int((len(result)-1)/2)]
            if s1 > s2:
                 s2 = s2 * m
            else:
                 s1 = s1 * m

            if s1 > 1:
                s1 = s1 - 1

            if s2 > 1:
                s2 = s2 - 1
            return s1 + s2

N = int(input())

d = divide(N)
a = rank(d)
print(calculate(a))

Submission status: Wrong Answer

Solution code:
data=int(input())
sum=20**6
 
for i in range(10**6):
  a=i+1
  if data%a==0:
    b=data//a
    if a+b<sum:
      sum=a+b
      
print(sum-2)

Submission status: Wrong Answer

Solution code:
data=int(input())
sum=20**6
 
for i in range(10**6):
  a=i+1
  if data%a==0:
    b=data/a
    if a+b<sum:
      sum=a+b
      
print(sum-2)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

a = int(input())
sum = []
result = 0

ub = int(pow(a, 0.5))

for i in range(2, ub):  
  (d, mod) = divmod(a, i)
  if mod == 0:
    sum.append(i + d)

if len(sum) == 0:
  print(a - 1)
else:
  sum.sort()
  print(sum[0] - 2)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = n-2

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

Submission status: Wrong Answer

Solution code:
a = []


def dis(n):
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            a.append(int(i))


num = int(input())
dis(num)
ans = 100000000
for e in a:
    if e + num // e - 2 < ans:
        ans = e + num // e - 2
    # ans = min(ans, e + num / e - 2)
print(ans)

Submission status: Wrong Answer

Solution code:
a = []


def dis(n):
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            a.append(int(i))


num = int(input())
dis(num)
ans = int(1e7)
for e in a:
    if e + num // e - 2 < ans:
        ans = e + num // e - 2
    # ans = min(ans, e + num / e - 2)
print(ans)

Submission status: Wrong Answer

Solution code:
a = []


def dis(n):
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            a.append(int(i))


num = int(input())
dis(num)
ans = 0
for e in a:
    continue
    # ans = min(ans, e + num / e - 2)
print(ans)

Submission status: Wrong Answer

Solution code:
a = []


def dis(n):
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            a.append(int(i))


num = int(input())
dis(num)
ans = 0
# for e in a:
#    ans = min(ans, e + num / e - 2)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
sum_ij = 1000000000000
for i in range(1, n+1):
  if (n%i==0):
    j = int(n/i)
    print('(i,j)=({},{})'.format(i, j))
    if(i+j < sum_ij):
      sum_ij = i+j-2
print(int(sum_ij))

Submission status: Wrong Answer

Solution code:
N = int(input())
i = 1
ans = 10 ** 10
while (i ** 2 <= N):
  if (N % i == 0):
    ans = min(ans, N // i + i - 2)
  i += 1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
fac = []
for i in range(1, math.floor(N**(1/2)) + 1):
  if (N % i == 0 and N // i <= i):
    print(N // i + i - 2)
    exit()

Submission status: Wrong Answer

Solution code:
s = input().split() #標準入力　sに値を入れる
n = int(s[0])
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()
l = len(divisors)
n1 = divisors[l // 2 - 1]
n2 = divisors[l // 2]
ans = n1 + n2 - 2
print(ans)

Submission status: Wrong Answer

Solution code:
s = input().split() #標準入力　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

n = int(s[0])
newdivisors = make_divisors(n)
l = len(newdivisors)
n1 = newdivisors[l // 2 - 1]
n2 = newdivisors[l // 2]
ans = n1 + n2 - 2
print(ans)

Submission status: Wrong Answer

Solution code:
s = input().split() #標準入力　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

n = int(s[0])
newdivisors = []
newdivisors = make_divisors(n)
n1 = newdivisors[len(newdivisors) // 2 - 1]
n2 = newdivisors[len(newdivisors) // 2]
ans = n1 + n2 - 2
print(ans)

Submission status: Wrong Answer

Solution code:
# 素因数分解
def prime_factorization(N):
    tmp = N
    ans = []
    for i in range(2, int(N ** 0.5) + 1):
        count = 0
        while tmp % i == 0:
            tmp //= i
            count += 1
        if count != 0:
            ans.append([i, count])
    if tmp != 1:
        ans.append([tmp, 1])
    if ans == []:
        ans.append([N, 1])
    return ans

N = int(input())
if len(prime_factorization(N)) == 1:
    print(N - 1)
    exit()
start = int(N ** 0.5) + 1
ans_a = 0
ans_b = 0
for a in range(start, 1, -1):
    b = N // a
    if N == a * b:
        ans_a = a
        ans_b = b
        break

print(ans_a + ans_b - 2)

Submission status: Wrong Answer

Solution code:
data=int(input())
sum=10**6
 
for i in range(10**6):
  a=i+1
  if data%a==0:
    b=data/a
    if a+b<sum:
      sum=a+b
      
print(sum-2)

Submission status: Wrong Answer

Solution code:
data=int(input())
sum=10**6

for i in range(10**6):
  a=i+1
  if data%a==0:
    b=data/a
    if a+b<sum:
      sum=a+b
print(sum-2)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
sq = math.ceil(math.sqrt(N))
li = []
for i in range(1,sq):
  if (N/i).is_integer():
    li.append(i+N/i-2)
print(int(min(li)))

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
import functools
import operator
def prod(li):
  return functools.reduce(operator.mul, li)

import sys
N = int(input())
factors = prime_factorize(N)
length = len(factors)
if length == 1:
  print(N-1)
else:
  cand1 = prod(factors[:-1])
  cand2 = factors[-1]
  if cand1<=cand2:
    print(cand1+cand2-2)
    sys.exit()
  else:
    last1 = cand1
    last2 = cand2
    for i in range(1,length-1):
      cand1 = prod(factors[i:-1])
      cand2 = factors[-1]*prod(factors[:i])
      if cand1 <= cand2:
        a = min(cand1+cand2,last1+last2)
        print(a-2)
        sys.exit()
      else:
        last1=cand1
        last2=cand2

Submission status: Wrong Answer

Solution code:
data=int(input())

sum=data
for i in range(data):
  a=i+1
  b=data/a
  if data%a==0 and a+b<sum:
    sum=a+b
print(sum-2)

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
rN=math.ceil(math.sqrt(N))
for i in range(rN,0,-1):
  if N//i == math.floor(N/i):
    print(i+(N//i)-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(int(i+n/i-2))
            if i != n // i:
                divisors.append(n//i)
    return divisors
ans = float("inf")
for i in make_divisors(int(input())):
    ans = min(ans,i)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

flag = True
s = math.floor(math.sqrt(N))
for i in range(s, 1, -1):
    if N % i == 0:
        ii = N // i
        print(i - 1 + ii - 1)
        flag = False
if flag:
    print(N - 1)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
import math

#移動回数はa+b-2。これを満たす座標(a,b)について、a,bの最小値
#探索範囲はsqrt(N)まで、a<=b
n = int(input())
ans = n

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

print(ans)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
import math

#移動回数はa+b-2。これを満たす座標(a,b)について、a,bの最小値
#探索範囲はsqrt(N)まで、a<=b
n = int(input())
ans = n

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

print(ans)

Submission status: Wrong Answer

Solution code:
from math import *

N = int(input())
r = N
for i in range(1,ceil(sqrt(N))):
    if N % i == 0:
        k = N//i
        if r > k+i:
            r = k+i

print(r-2)

Submission status: Wrong Answer

Solution code:
from math import *

n = int(input())

mn = n

i1 = 0
i2 = n

for i in range(1,ceil(sqrt(n))):
    
    if(n%i==0):
        k = n//i
        if(abs(k-i)<mn):
            i1 = i
            i2 = k
            
ans = i1 + i2 -2

print(ans)

Submission status: Wrong Answer

Solution code:
from math import sqrt

n=int(input())
a=int(sqrt(n))
b=n//a
d=[]
for i in range(1,a+1):
    if n//i==n/i:
        if n//i == i:
            d.append(i)
            
        else:
            d.extend([i,n//i])



if len(d) % 2 == 1:
    print(d[-1]**2-2)

else:
    print(d[-1]+d[-2]-2)

Submission status: Wrong Answer

Solution code:
n = int(input())

p = 1
if n%2 == 0:
    p = 2

for i in range(3, int(n**0.5)+1, 2):
    if n%i == 0:
        p = i

print(int(p+n/p-2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors
N = int(input())
factors = prime_factors(N)
a, b = 1, 1
for elem in factors:
  if elem > a and elem > b:
    a *= b
    b = elem
  else:
    if a <= b:
      a *= elem
    else:
      b *= elem
print(a+b-2)

Submission status: Wrong Answer

Solution code:
def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors
N = int(input())
factors = prime_factors(N)
print(factors)
a, b = 1, 1
for elem in factors:
  if elem > a and elem > b:
    a *= b
    b = elem
  else:
    if a <= b:
      a *= elem
    else:
      b *= elem
print(a+b-2)

Submission status: Wrong Answer

Solution code:
def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors
N = int(input())
factors = prime_factors(N)
a, b = 1, 1
for elem in factors:
  if a <= b:
    a *= elem
  else:
    b *= elem
print(a+b-2)

Submission status: Wrong Answer

Solution code:
def prime_factors(n):
    i = 2
    factors = 1
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors = i
    if n > 1:
        factors = n
    return factors
N = int(input())
factor = prime_factors(N)
print(int(factor + N/factor - 2))

Submission status: Wrong Answer

Solution code:
def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors = i
    if n > 1:
        factors = n
    return factors
N = int(input())
factor = prime_factors(N)
print(int(factor + N/factor - 2))

Submission status: Wrong Answer

Solution code:
def prime_factors(n):
    i = 2
    factors = 1
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors = i
    if n > 1:
        factors = i
    return factors
N = int(input())
large_factor = prime_factors(N)
print(int(large_factor+(N/large_factor)-2))

Submission status: Wrong Answer

Solution code:
def prime_factors(n):
    i = 2
    factors = 1
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors = i
    if n > 1:
        factors = i
    return factors
N = int(input())
large_factor = prime_factors(N)
print(large_factor+(N/large_factor)-2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# 191027 C
import heapq
def prime_factorize(n):
    a = [1,1]
    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())
pfac = prime_factorize(N)
nlen = len(pfac)
heapq.heapify(pfac)
tmpa = 0
for i in range(nlen-2):
    tmpa = heapq.heappop(pfac)
    tmpa = tmpa * heapq.heappop(pfac)
    heapq.heappush(pfac,tmpa)
#print(pfac)
print(max(pfac[0]-1,0) + max(pfac[1]-1,0))

Submission status: Wrong Answer

Solution code:
# 191027 C
import heapq
def prime_factorize(n):
    a = [1,1]
    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())
pfac = prime_factorize(N)
nlen = len(pfac)
heapq.heapify(pfac)
tmpa = 0
for i in range(nlen-2):
    tmpa = heapq.heappop(pfac)
    tmpa = tmpa * heapq.heappop(pfac)
    heapq.heappush(pfac,tmpa)

print(max(pfac[0]-1,0) + max(pfac[1]-1,0))

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,10):
  for j in range(1,10):
      if(i*j==n):
          print ("Yes")
          sys.exit()

print ("No")

Submission status: Wrong Answer

Solution code:
# 191027 C
import heapq
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())
pfac = prime_factorize(N)
nlen = len(pfac)
heapq.heapify(pfac)
tmpa = 0
for i in range(nlen-2):
    tmpa = heapq.heappop(pfac)
    tmpa = tmpa * heapq.heappop(pfac)
    heapq.heappush(pfac,tmpa)
print(sum(pfac) - 2)

Submission status: Wrong Answer

Solution code:
N = int(input())
import copy
sumi = 0
ans = 0
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

a = factorization(N)
for i in range(len(a)):
  sumi = sum(a[i])
  if i == 0:
    ans = sum(a[i])
  else:
    if ans > sumi:
      ans = sumi
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
import copy
sumi = 0
ans = 0
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

a = factorization(N)
for i in range(len(a)):
  sumi = sum(a[i])
  print(sumi)
  if i == 0:
    ans = sum(a[i])
  else:
    if ans > sumi:
      ans = sumi
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
import copy
sumi = 0
ans = 0
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

a = factorization(N)
for i in range(len(a)):
  sumi = sum(a[i])
  if i == 0:
    ans = sum(a[i])
  else:
    if ans < sumi:
      ans = sumi
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
import copy
sum = 0
ans = 0
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

a = factorization(N)
for i in range(len(a)):
  sum = copy.copy(a[i])
  if i == 0:
    ans = copy.copy(a[i])
  else:
    if ans < sum:
      ans = sum
print(ans)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
ans=n

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = N-1

if N%2 ==0:
  b=int(N/2)
else:
  b=int((N-1)/2)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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