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):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
    N = I()
    ans = inf
    max_sq = int(round(math.sqrt(N))) + 1
    for i in range(1, max_sq):
        if N % i != 0:
            continue
        j = N / i
        ans = min(ans, i+j-2)
    print(ans)
main()



import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
    N = I()
    ans = N - 1
    max_sq = int(math.sqrt(N)) + 1
    for i in range(1, max_sq):
        if N % i != 0:
            continue
        j = N / i
        ans = min(ans, i+j-2)
    print(ans)

main()



import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
    N = I()
    ans = inf
    max_sq = int(round(math.sqrt(N))) + 1
    for i in range(1, max_sq):
        if N % i != 0:
            continue
        j = N / i
        ans = min(ans, i+j-2)
    print(ans)

main()



import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
def main():
    N = int(input())
    ans = N-1
    max_sq = int(math.sqrt(N)+1)
    for i in range(1, max_sq):
        if N % i != 0:
            continue
        j = N / i
        ans = min(ans, i+j-2)
    print(ans)
main()



import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
    N = I()
    ans = N - 1
    max_sq = int(math.sqrt(N)) + 1
    for i in range(1, max_sq):
        if N % i != 0:
            continue
        j = N // i
        ans = min(ans, i+j-2)
    print(ans)
main()




Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted