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:
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

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

    ret = float('inf')
    for i in range(1, 10):
        q, mod = divmod(N, i)
        if mod == 0:
            j = N // i
            ret = min(ret, ((j-1)+(i-1)))

    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# #!/usr/bin/env python3
# # -*- coding: utf-8 -*-


def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(n // i)
        i += 1
    table = list(set(table))
    return table


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

    div = divisor(N)
    div.sort()

    print(div[len(div) // 2] + div[len(div) // 2 - 1] - 2)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import sqrt
n=int(input())
ans=n
for i in range(1,int(sqrt(n))):
  if n%i==0:
    ans=min(ans,abs(i-1)+abs(n//i-1))
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

list_n = make_divisors(n)

a = len(list_n)
ans = []
for i in range(0, a-1, 2):
    ans.append(list_n[i]+list_n[i+1])

ans.sort()

print(ans[0]-2)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

ans = 10**13


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

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

ans = 10**13


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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())

tmp = 10 ** 6
tmp2 = 1
tmp3 = 1
for i in range(1, 10 ** 6):
    if n % i == 0 and i + (n / i) < tmp:
        tmp = i + (n // i)
        tmp2 = i
        tmp3 = n // i
print(tmp2 + tmp3 - 2)

Submission status: Wrong Answer

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

num = int(input())
#matrix = factorization(num)
num_list = prime_factorize(num)
num_list.sort()
#for i in range(0,len(matrix)):
#  for j in range(0,matrix[i][1]):
#    num_list.append(matrix[i][0])

judge_a = 1
judge_b = 1

for i in range(0,len(num_list)):
  if judge_a >= judge_b:
    judge_b = judge_b*num_list[len(num_list)-1-i]
  else:
    judge_a = judge_a*num_list[len(num_list)-1-i]
  
ans = (judge_a-1)+(judge_b-1)
      
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

num = int(input())
#matrix = factorization(num)
num_list = prime_factorize(num)
num_list.sort()
#for i in range(0,len(matrix)):
#  for j in range(0,matrix[i][1]):
#    num_list.append(matrix[i][0])

judge_a = num_list[len(num_list) -1]
judge_b = 1

for i in range(0,len(num_list)-1):
  if judge_a >= judge_b:
    judge_b = judge_b*num_list[len(num_list)-2-i]
  else:
    judge_a = judge_a*num_list[len(num_list)-2-i]
  
ans = (judge_a-1)+(judge_b-1)
      
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

num = int(input())
#matrix = factorization(num)
num_list = prime_factorize(num)

#for i in range(0,len(matrix)):
#  for j in range(0,matrix[i][1]):
#    num_list.append(matrix[i][0])

judge_a = num_list[len(num_list) -1]
judge_b = 1

for i in range(0,len(num_list)-1):
  if judge_a >= judge_b:
    judge_b = judge_b*num_list[len(num_list)-2-i]
  else:
    judge_a = judge_a*num_list[len(num_list)-2-i]
  
ans = (judge_a-1)+(judge_b-1)
      
print(ans)

Submission status: Wrong Answer

Solution code:
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

num = int(input())
matrix = factorization(num)
num_list = []

for i in range(0,len(matrix)):
  for j in range(0,matrix[i][1]):
    num_list.append(matrix[i][0])

judge_a = num_list[len(num_list) -1]
judge_b = 1

for i in range(0,len(num_list)-1):
  if judge_a >= judge_b:
    judge_b = judge_b*num_list[len(num_list)-2-i]
  else:
    judge_a = judge_a*num_list[len(num_list)-2-i]
  
ans = (judge_a-1)+(judge_b-1)
      
print(ans)

Submission status: Wrong Answer

Solution code:
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

num = int(input())
matrix = factorization(num)
num_list = []

for i in range(0,len(matrix)):
  for j in range(0,matrix[i][1]):
    num_list.append(matrix[i][0])

judge_a = num_list[len(num_list) -1]
judge_b = 1

for i in range(0,len(num_list)-1):
  if judge_a >= judge_b:
    judge_b = judge_b*num_list[len(num_list)-2-i]
  elif judge_b > judge_a:
    judge_a = judge_a*num_list[len(num_list)-2-i]
  
ans = (judge_a-1)+(judge_b-1)
      
print(ans)

Submission status: Wrong Answer

Solution code:
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

num = int(input())
matrix = factorization(num)
num_list = []
num_0 = 1

for i in range(0,len(matrix)):
  a = matrix[i][1] // 2
  if not a == 0:
    num_0 = num_0 * matrix[i][0] * a
  sign = matrix[i][1] % 2
  if sign == 1:
    num_list.append(matrix[i][0])

if num_list == []:
  ans = (num_0-1)+(num_0-1)
else:
  judge_a = num_list[len(num_list) -1]
  judge_b = 1
  for i in range(0,len(num_list)-1):
    if judge_a >= judge_b:
      judge_b = judge_b*num_list[len(num_list)-2-i]
    elif judge_b > judge_a:
      judge_a = judge_a*num_list[len(num_list)-2-i]
  ans = (num_0*judge_a-1)+(num_0*judge_b-1)
      
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import sqrt
N = int(input())
ans = 10**12+1
for x in range(1, int(sqrt(N))):
  if N % x == 0:
    y = N // x
  l = (x - 1) + (y - 1)
  ans = min(ans, l)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
i=2
m = n
root_n = n**0.5
a = []
while m>1 and i <= root_n:
  while m%i==0:
    a.append(i)
    m //= i
  i += 1
if m>1:
  a.append(m)
b = [1]
min_a = min(a)
for i in a[::-1]:
  max_b = max(b)
  for j in b:
    ij = i*j
    if (ij <= root_n and ij > max_b) or (ij <= root_n//min_a):
      b.append(ij)
  if max(b) == root_n:
    break
max_b = max(b)
print(max_b+n//max_b-2)

Submission status: Wrong Answer

Solution code:
n = int(input())
i=2
m = n
root_n = n**0.5
a = []
while m>1 and i <= root_n:
  while m%i==0:
    a.append(i)
    m //= i
  i += 1
if m>1:
  a.append(m)
b = [1]
for i in a[::-1]:
  for j in b:
    if i*j <= root_n:
      b.append(i*j)
  if max(b) == root_n:
    break
max_b = max(b)
print(max_b+n//max_b-2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools
from operator import mul

n = int(input())
k = n
ans = n - 1
prime = []

while k != 1:
    for i in range(2,int(k**0.5)+1):
        if k % i == 0:
            prime.append(i)
            k /= i
            break
    else:
        prime.append(int(k))
        k = 1

div = list(itertools.accumulate(prime,mul))

for i in div:
    ans = min(ans,i + n//i -2)

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import itertools

n = int(input())
ans = n -1
prime = []

while n != 1:
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            prime.append(i)
            n /= i
            break
    else:
        prime.append(int(n))
        n = 1

a = 1
b = 1

while True:
    pc = collections.Counter(prime)
    pc2 = [int(i[0]) for i in pc.items() if i[1] >= 2]

    if not pc2:
        break

    for i in pc2:
        a *= i
        b *= i
        prime.remove(i)
        prime.remove(i)

for bit in range(1 << len(prime)):
    for i in range(len(prime)):
        if bit >> i & 1:
            a *= prime[i]
        else:
            b *= prime[i]

    ans = min((a+b-2,ans))

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

mul = []
for i in range (1,round(N**(1/2) + 1)):
    if N%i == 0:
        mul.append(i)
        mul.append(N//i)
print(mul)

min = mul[0] + mul[1]
for i in range (0,len(mul),2):
    print(i)
    if mul[i] + mul[i+1] <= min:
        min = mul[i] + mul[i+1]

print(min-2)

Submission status: Wrong Answer

Solution code:
n=int(input())
#n=i*jを満たすi,jで，i+jが最小

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 product(lis):
    res=1
    for i in range(len(lis)):
        res*=lis[i]
    return res

lis=prime_factorize(n)
lis.sort()
lis_a=[lis[i] for i in range(len(lis)) if i%2==0]
lis_b=[lis[i] for i in range(len(lis)) if i%2!=0]
print(product(lis_a)+product(lis_b)-2)

Submission status: Wrong Answer

Solution code:
def prime_number(x):
    sieve = []
    for i in range(2,int(x**(0/5))+1):
        for j in range(2,i):
            if i%j==0:
                break
        else:
            sieve.append(i)
    sieve.append(2)

    for i in range(len(sieve)):
        prime = sieve[i]
        if x%prime==0:
            return False
            break
    else:
        return True


n = int(input())

if prime_number(n):
    print(n-1)
else:
    i = 1
    j = n//i
    divisor_lst = []
    while i<=j:
        i += 1
        j = n//i
        if n%i==0:
            divisor_lst.append([i,j])

    n_x = divisor_lst[-1][0]
    n_y = divisor_lst[-1][1]
    print(n_x+n_y-2)

Submission status: Wrong Answer

Solution code:
def prime_number(x):
    if x==2 or x==3:
        return True
    else:
        if x%2==0 or x%3==0:
            return False
        else:
            divisor_lst = [1,x]
            for i in range(1,x+1):
                if i not in divisor_lst and x%i==0:
                    return False
                else:
                    return True

n = int(input())

if prime_number(n):
    print(n-1)
else:
    i = 1
    j = n//i
    divisor_lst = []
    while i<=j:
        i += 1
        j = n//i
        if n%i==0:
            divisor_lst.append([i,j])

    n_x = divisor_lst[-1][0]
    n_y = divisor_lst[-1][1]
    print(n_x+n_y-2)

Submission status: Wrong Answer

Solution code:
N=int(input())
ans=10**13
from math import sqrt
for i in range(1, int(sqrt(N))):
    if N%i==0:
        temp=(i-1)+(N//i-1)
        if temp<ans:
            ans=temp
print(ans)

Submission status: Wrong Answer

Solution code:
def prime_factorization(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())

a = prime_factorization(N)
b = [0]*len(a)
test = [0]*len(a)

for i in range(len(a)):
    b[i] = N//a[i]
    test[i] = a[i]+b[i]

print(int(min(test)-2))

Submission status: Wrong Answer

Solution code:
def prime_factorization(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())

a = prime_factorization(N)
b = [0]*len(a)
test = [0]*len(a)

for i in range(len(a)):
    b[i] = N//a[i]
    test[i] = a[i]+b[i]

print(min(test)-2)

Submission status: Wrong Answer

Solution code:
def prime_factorization(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())

a = prime_factorization(N)
j = a[-1]
i = N//j
j_1 = a[-1]*a[-2]
i_1 = N//j_1
if i+j < i_1+j_1:
    print(i+j-2)
else:
    print(i_1+j_1-2)

Submission status: Wrong Answer

Solution code:
def prime_factorization(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())

a = prime_factorization(N)
j = a[-1]
i = N//j
print(i+j-2)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

    # divisors.sort()
    return divisors

n_list = make_divisors(n)
n_ans = []
print(n_list)
for i in range(0, len(n_list)-1, 2):
    n_ans.append(n_list[i]+n_list[i+1])

n_ans.sort()

print(n_ans[0]-2)

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

n_list = prime_factorize(n)
n_list.insert(0, 1)
n_score = []

a = 1
n_list_2 = set(n_list)
n_list_2 = list(n_list_2)
for j in range(len(n_list_2)):
    a = n_list_2[j]
    n_list.remove(a)
    for i in range(len(n_list)):
        a = a * n_list[i]
        b = n / a
        n_score.append(int(a+b))

n_score.sort()

print(n_score[0]-2)

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

n_list = prime_factorize(n)
n_list.insert(0, 1)
n_score = []

a = 1
n_list_2 = set(n_list)
n_list_2 = list(n_list_2)
for j in range(len(n_list_2)):
    a = n_list_2[j]
    n_list.remove(a)
    for i in range(len(n_list)):
        a = a * n_list[i]
        b = n / a
        n_score.append(int(a+b))

n_score.sort()
print(n_score)
print(n_score[0]-2)

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

n_list = prime_factorize(n)
n_list.insert(0, 1)
n_score = []
print(n_list)
a = 1
n_list_2 = set(n_list)
n_list_2 = list(n_list_2)
print(n_list_2)
for j in range(len(n_list_2)):
    a = n_list_2[j]
    for i in range(len(n_list)):
        a = a * n_list[i]
        b = n / a
        n_score.append(int(a+b))

n_score.sort()

print(n_score[0]-2)

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

n_list = prime_factorize(n)
n_list.insert(0, 1)
n_score = []

a = 1

for i in range(len(n_list)):
    a = a * n_list[i]
    b = n / a
    n_score.append(int(a+b))

n_score.sort()

print(n_score[0]-2)

Submission status: Wrong Answer

Solution code:
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys
import itertools

# import math

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10 ** 9

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

Submission status: Wrong Answer

Solution code:
n=int(input())
lim=int(n**.5)
step=float("inf")
for i in range(1,lim):
  a=i
  if n%a==0:
    b=n//a
    step=min(step,a+b-2)
print(step)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
flag = 100000000000

for i in range(1, int(math.sqrt(n))+1):
    x = n / i
    y = n % i

    if y == 0:
        z = x+i
        if z < flag:
            flag = z

print(int(flag-2))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

a = pow(10,12)

is_not_prime = False
#for k in range(2, int(math.sqrt(N)) + 1):
#    if N % k == 0:
#        is_not_prime = True
#        break
#if is_not_prime:
for i in range(1, int(math.sqrt(N+1))):
    #print(i)
    j = N/i
    if j.is_integer():

        if (i+int(j)) < a:
            a = i+int(j)
    #if j < 2:
    #    break

print(a - 2)
#else:
#    print(N - 1)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

a = pow(10,12)

is_not_prime = False
#for k in range(2, int(math.sqrt(N)) + 1):
#    if N % k == 0:
#        is_not_prime = True
#        break
#if is_not_prime:
for i in range(1, int(math.sqrt(N))):
    print(i)
    j = N/i
    if j.is_integer():

        if (i+int(j)) < a:
            a = i+int(j)
    #if j < 2:
    #    break

print(a - 2)
#else:
#    print(N - 1)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

a = pow(10,12)

is_not_prime = False
for k in range(2, int(math.sqrt(N)) + 1):
    if N % k == 0:
        is_not_prime = True
        break
if is_not_prime:
    for i in range(1, int(N/3)):
        print(i)
        j = N/i
        if j.is_integer():

            if (i+int(j)) < a:
                a = i+int(j)
        if j < 2:
            break

    print(a - 2)
else:
    print(N - 1)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

a = pow(10,12)

is_not_prime = False
for k in range(2, int(math.sqrt(N)) + 1):
    if N % k == 0:
        is_not_prime = True
        break
if is_not_prime:
    for i in range(1, int(math.sqrt(N)) + 1):
        print(i)
        j = N/i
        if j.is_integer():

            if (i+int(j)) < a:
                a = i+int(j)
        if j < 2:
            break

    print(a - 2)
else:
    print(N - 1)

Submission status: Wrong Answer

Solution code:
from math import sqrt, floor

def solve(n):
    m = floor(sqrt(n)) + 1
    for i in range(m + 1, 1, -1):
        if n % i == 0:
            return i + n // i - 2

_n = int(input())
print(solve(_n))

Submission status: Wrong Answer

Solution code:
import math

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

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy

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

def check(li):
    m = 100000000
    for i in range(len(li)):
        left = int(numpy.prod(li[:i]))
        right = int(numpy.prod(li[i:]))
        m = min(m, (left-1)+(right-1))
    return m

n = int(input())
nn = prime_factorize(n)
length = len(nn)
#print(nn)

if length == 1:
    print(n-1)
else:
    print(check(nn))

Submission status: Wrong Answer

Solution code:
import numpy

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

def check(li):
    m = 100000000
    for i in range(len(li)):
        left = int(numpy.prod(li[:i]))
        right = int(numpy.prod(li[i:]))
        m = min(m, (left-1)+(right-1))
    return m

n = int(input())
nn = prime_factorize(n)
length = len(nn)
print(check(nn))

Submission status: Wrong Answer

Solution code:
def main():
  n = int(input())
  i = int((n)**0.5) + 1
  while i * i > n: i -= 1
  while i >= 1:
    if n % i == 0:
      print(i+n//i)
      return
    i -= 1
main()

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
num=[]

for i in range(1,int(math.sqrt(n))):
    if n%i==0:
        num.append([i,n//i])
maxv = 10**13
for i in num:
    if maxv > sum(i):
        maxv = sum(i)
print(maxv-2)

Submission status: Wrong Answer

Solution code:
n = int(input())
num=[]

for i in range(1,n//2):
    if n%i==0:
        num.append([i,n//i])
maxv = 10**13
for i in num:
    if maxv > sum(i):
        maxv = sum(i)
print(maxv-2)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

mi = INF
for i in range(1, 10**6):
 	if is_integer_num(N/i):
 		if mi > i + N//i:
	 		mi = i + N//i

print(mi - 2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = []
b = []
for i in range(1,10**6):
	if N % i == 0:
		b.append(N // i)
		a.append(i)
	if i > N:
		break
ab = 10**7
for i in range(len(a)):
	ab = min(ab,(a[i]-1)+(b[i]-1))
print(ab)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 1
i=1
while i*i<n:
    if n%i==0:
        ans = i
    i+=1

ans += n//ans
ans -= 2
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
for i in range(int(N**0.5)+1, 1, -1):
  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**0.5)+1, -1):
  if N % i == 0:
    print(i + (N // i) - 2)
    break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
minimum = 10**14
def prime_divisors(X):
    L=[]
    for i in range(2,math.floor(X**0.5)):
        if X % i == 0:
            L.append(i)
    return L
N = int(input())
L = prime_divisors(N)
L.append(1)
for prime in L:
    if (prime-1 + N//prime - 1) < minimum:
        minimum = (prime-1 + N//prime - 1)
print(minimum)

Submission status: Wrong Answer

Solution code:
N = int(input())
count = 1
while True:
    count = count + 1
    if N % count == 0:
        tmp = N / count
        print(int(tmp-1+count-1))
        break

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
div=[]
for i in range(1,math.ceil(n**0.5)):
    if n%i==0:
        div.append(i)
        if i!=n//i:
            div.append(n//i)
div.sort()
print(div[len(div)//2]+div[len(div)//2-1]-2)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
div=[]
for i in range(1,math.ceil(n**0.5)):
    if n%i==0:
        div.append(i)
        if i!=n//i:
            div.append(n//i)
div.sort()
print(div)
if len(div)%2==0:
    print(div[len(div)//2]+div[len(div)//2-1]-2)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

print(now_answer)

Submission status: Wrong Answer

Solution code:
N = int(input())

min_combi = (1, N)

for n in range(2, int(N**0.5)):
    if N % n == 0:
        combi = (n, int(N/n))
        if sum(min_combi)-2 > sum(combi)-2:
            min_combi = combi

print(sum(min_combi)-2)

Submission status: Wrong Answer

Solution code:
N = int(input())

min_combi = (1, N)

for n in range(2, int(N**0.5)):
    if N % n == 0:
        combi = (n, N//n)
        if sum(min_combi)-2 > sum(combi)-2:
            min_combi = combi

print(sum(min_combi)-2)

Submission status: Wrong Answer

Solution code:
N = int(input())

min_combi = (1, N)

for n in range(2, int(N**0.5)):
    if N % n == 0:
        combi = (n, N//n)
        if min_combi[0] + min_combi[1] > n + N//n:
            min_combi = combi

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

Submission status: Wrong Answer

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

min_count = 1000000000000
pre_i = 0
pre_j = 0

for i in range(1, int(math.sqrt(n))):
  j = n / i
  f, s = math.modf(j)
  if pre_i == j and pre_j == i:
    break
  if str(f) == "0.0":
    count = (i - 1) + (j - 1)
    if count < min_count:
      min_count = count
    pre_i = i
    pre_j = j

print("{:.0f}".format(min_count))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

x = 0
y = 0

ans = 100000000000

for n in range(1, math.floor(math.sqrt(N)) + 1):  
  if N % n == 0:
    x = n
    y = math.floor(N / x)

    t = ((x - 1) + (y - 1))

    if ans > t:
      ans = t

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
from math import sqrt
def get_divs(n):
  divs = []
  for i in range(1, int(sqrt(n))):
    if n % i == 0:
      divs.append((i, n // i))
  return divs

divs = get_divs(N)
ans = float('inf')
for x, y in divs:
  ans = min(ans, (x + y - 2))
print(ans)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
import math
import time
import numpy as np
import collections
from collections import deque
import queue
import copy

# 最大公約数
def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z

# 幅優先探索(BFS)でスタート座標(x, y)からの最大距離返す
def bfs(SS, x, y, H, W):#入力(座標系(迷路), x, y, xの端, yの端)
  x_next = [0, 0, -1, 1]
  y_next = [1, -1, 0, 0]
  tempx = x
  tempy = y
  mlength = 0
  q = deque()
  xytuple = (x, y, 0)
  q.append(xytuple)


  while q:
    xytuple = q.popleft()
    SS[xytuple[0]][xytuple[1]] = "x" #探索した場所は探索できないようにする
    for i in range(4): #このforで上下左右を調べてる
      tempx = xytuple[0] + x_next[i]
      tempy = xytuple[1] + y_next[i]
      #print(tempx, tempy, xytuple[2])
      #print(S)
      if(0 <= tempx and tempx < H and 0 <= tempy and tempy < W and SS[tempx][tempy] == "."):
        temptuple = (tempx, tempy, xytuple[2]+1)
        SS[temptuple[0]][temptuple[1]] = "x" #探索した場所は探索できないようにする
        mlength = max(mlength, xytuple[2] +1)
        q.append(temptuple)
      #print(q)
  return mlength


#X = str(input()).split()
#a = [int(x) for x in input().split()]
N = int(input())

for i in range(math.floor(math.sqrt(N))):
  if((math.floor(math.sqrt(N)+1+i))*(math.floor(math.sqrt(N))-i)==N):
    a = math.floor(math.sqrt(N)+1+i)
    b = math.floor(math.sqrt(N))-i
    break
  if(math.floor(math.sqrt(N))-i==1):
    a = 0
    b = N+1
    break

ans = a+b-2
print(ans)

Submission status: Wrong Answer

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