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.

Solution (Python):
import math

def factor(n):
    r = []
    tmp = n
    for i in range(2, int(math.sqrt(n)) + 1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            r.append((i, cnt))
    if tmp != 1:
        r.append((tmp, 1))
    if not r:
        r.append((n, 1))
    return r

def all_pat(l):
    k = [0] * len(l) 
    t = [tuple(k)]
    while True:
        k[0] += 1
        for i in range(len(l)):
            if k[i] <= l[i][1]:
                break
            k[i] = 0
            if i == len(l) - 1:
                return t
            k[i + 1] += 1
        t.append(tuple(k))
    

def main():
    a = int(input())
    l = factor(a)
    p = all_pat(l)
    t = []
    for i in p:
        m = 1
        for j in range(len(l)):
            m *= l[j][0] ** i[j]
        t.append(m + (a // m))
    print(min(t) - 2)
            


if __name__ == '__main__':
    main()

Solution (Python):

import math


def solve(*args: str) -> str:
    n = int(args[0])

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


if __name__ == "__main__":
    print(solve(*[input() for _ in range(1)]))

Solution (Python):
import math

n = int(input())

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

Solution (Python):
N = int(input())
import math
A = []
for i in range(1,int(math.sqrt(N))+1):
    if N % i == 0:
        A.append(i+N/i-2)
print(int(min(A)))

Solution (Python):
N = int(input())
import math
def devision(N):
    i = int(math.sqrt(N))
    a = list()
    for j in range(1,i+1):
        if N % j == 0:
            a.append(j)
    return a[len(a)-1]
def move(N):
    return (devision(N) + N//devision(N) - 2)
print(move(N))

Solution (Python):
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


divisors=make_divisors(n)

minval = 10**15

if len(divisors)%2 == 0:
    
    for i in range(len(divisors)//2):
        a,b = divisors[i],divisors[len(divisors)-1-i]
        if (a+b)<minval:
            minval = a+b
            
if len(divisors)%2 == 1:
    for i in range(len(divisors)//2+1):
        if i ==len(divisors)//2:
            a,b = divisors[i],divisors[i]
        else:
            a,b = divisors[i],divisors[len(divisors)-1-i]
        
        if (a+b)<minval:
            minval = a+b
print(minval-2)

Solution (Python):
N = int(input())

ret = [1, N]
for i in range(1,N):
    if i > N // i:
        break
        
    if N % i == 0:
        ret = [i, N // i]

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

Solution (Python):
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


n = int(input())
li = make_divisors(n)

ans = 10 ** 12
for i in li:
    j = n // i
    tmp_ans = (i-1)+(j-1)
    if tmp_ans < ans:
        ans = tmp_ans
print(ans)

Solution (Python):

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

yakusu_list = make_divisors(N)

mid = yakusu_list[len(yakusu_list) // 2]

mid2 = N // mid

print((mid - 1) + (mid2 - 1))