Problem: 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.

Submission attempts (in order):
# -*- coding: utf-8 -*-
import sys
import itertools
import math
#w=input()
i=0
j=0
N=int(input())
Nori=N
#T, A=input().split()
#S=input()
#T=input()
#S_list=list(S)
#h_list=  list(map(int, input().split(" ")))
#M=int(input())

#print(T_list[1])
#T=int(T)
#A=int(A)

     
#dp=[['' for i in range(2)] for j in range(N)]


#S_list=[]
#sentence_list=[]
#total=0



# ID_list.append(i+1)
#print(ID_list)







:
#  ppixel_list=list(input())
    
#print(pixel_list)
#high_pixel_list =[['' for i in range(W)]for j in range(2*H)]
#print(high_pixel_list)

#print(a_list)
first_term=0
second_term=0


     

  
     


     

#  x[i], y[i] = map(int, input().split())


     
     
distance = 0
#comb = list(itertools.permutations(l))




#    distance += math.sqrt((x[comb[i][j]]-x[comb[i][j+1]])**2 + (y[comb[i][j]]-y[comb[i][j+1]])**2)

#print(distance/len(comb))
i=0
j=0
movepoint=10**15




# for j in range(N):
#     if N % (j+1)==0:
#         i=N/(j+1)
#         movepoint=min(movepoint,(i+j+1-2))
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)
x=1
y=Nori
if a==[]:
    print(Nori-1)
    sys.exit()

for i in range(len(a)):
    #print(x,y)
    movepoit=min(movepoint,(x+y-2))
    x=x*a[i]
    y=y/a[i]
    #print(x,y)
print(int(movepoit))
#print(int(movepoint))
# dp[i+1][j]=max(dp[i][j]+a_b_c_list[i],dp[i][j],dp[i][j])



# -*- coding: utf-8 -*-
import sys
import itertools
import math
#w=input()
i=0
j=0
N=int(input())
#T, A=input().split()
#S=input()
#T=input()
#S_list=list(S)
#h_list=  list(map(int, input().split(" ")))
#M=int(input())

#print(T_list[1])
#T=int(T)
#A=int(A)

     
#dp=[['' for i in range(2)] for j in range(N)]


#S_list=[]
#sentence_list=[]
#total=0



# ID_list.append(i+1)
#print(ID_list)







:
#  ppixel_list=list(input())
    
#print(pixel_list)
#high_pixel_list =[['' for i in range(W)]for j in range(2*H)]
#print(high_pixel_list)

#print(a_list)
first_term=0
second_term=0


     

  
     


     

#  x[i], y[i] = map(int, input().split())


     
     
distance = 0
#comb = list(itertools.permutations(l))




#    distance += math.sqrt((x[comb[i][j]]-x[comb[i][j+1]])**2 + (y[comb[i][j]]-y[comb[i][j+1]])**2)

#print(distance/len(comb))
i=0
j=0
movepoint=10**15




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

print(int(movepoint))
# dp[i+1][j]=max(dp[i][j]+a_b_c_list[i],dp[i][j],dp[i][j])



# -*- coding: utf-8 -*-
import math
     
N = int(input())
     
m = N - 1
for i in range(1, math.floor(N ** 0.5) + 1):


        if N % i == 0:
            m = min(m, math.floor(i + (N / i) - 2))
     
print(m)

# N = int(input())
     
# m = N - 1


#             m = min(m, math.floor(i + (N / i) - 2))

# print(m)


Verdicts: Wrong Answer

Wrong Answer

Accepted