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:
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

sys.setrecursionlimit(1000000)
dire, dire8 = [[1, 0], [0, 1], [-1, 0], [0, -1]], [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets, ALPHABETS = "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD, INF = 1000000007, float("inf")

def factors(n):
    d = []
    a = 2
    while n >= a ** 2:
        if n % a == 0:
            n //= a
            d.append(a)
        else:
            a += 1
    d.append(n)
    return d

def main():
    N = I()
    i, j = 1, 1

    for div in factors(N):
        if i >= j:
            j *= div
        else:
            i *= div
    print(i + j - 2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def 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())
nf=factorize(n)
wow=10**12+1
ok=[]
for i in range(len(nf)):
    pair=n//nf[i]
    if pair+nf[i]<wow:
        ok.append([pair,nf[i]])
        wow=pair+nf[i]
print(ok[-1][0]+ok[-1][1]-2)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
sq = int(math.sqrt(n))

i=sq
for i in range(sq,0,-1):
    if n%i==0:
        j=n//i
        
print(i+j-2)

Submission status: Wrong Answer

Solution code:
n=int(input())
import math
ans=10**12
for i in range(1,int(math.sqrt(n))):
  if n%i!=0:
    continue
  j=n/i
  ans=min(ans, i+j-2)
if ans ==10**12:
  print(n-1)
else:
  print(int(ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
import math
ans=100000000000
for i in range(1,int(math.sqrt(n))):
  if n%i!=0:
    continue
  j=n/i
  ans=min(ans, i+j-2)
if ans ==100000000000:
  print(n-1)
else:
  print(int(ans))

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())


l=list(make_divisors(n))

l.sort()

ans=-1
for i,ll in enumerate(l):
  if i!=len(l)-1 and ll*l[i+1]==n:
    ans=ll+l[i+1]-2
if n==1:
  print(0)
elif ans!=-1:
  print(ans)
else:
  print(n+1)

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())


l=list(make_divisors(n))

l.sort()

ans=-1
for i,ll in enumerate(l):
  if i!=len(l)-1 and ll*l[i+1]==n:
    ans=ll+l[i+1]-2
if n==1:
  print(0)
elif ans!=-1:
  print(ans)
else:
  print(n)

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())


l=list(make_divisors(n))

l.sort()

ans=-1
for i,ll in enumerate(l):
  if i!=len(l)-1 and ll*l[i+1]==n:
    ans=ll+l[i+1]-2
if n==1:
  print(0)
elif ans!=-1:
  print(ans)
else:
  print(n-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
i = 1 
res =N
flag = True
if N ==1:
  print(0)
else:
  k = int(N**0.5)
  for j in range(1,k+1):
    k = N / j
    b = int(k)
    if k-b == 0:
      res = min(res,i+b-2)
print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = 0
k = 0
for x in range(exit()):
  for y in range(exit()):
    if n % y == 0 and n % x == 0:
      s = x
      k = y
      exit()
print((s - 1) + (k - 1))

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

first = last = 1
primeFactor = prime_factorize(N)
primeFactor.reverse()

even = primeFactor[::2]
odd = primeFactor[1::2]
even.extend(odd)

for x in even:
    if first*x <= N**0.5 :
        first *= x
    else :
        last *= x

print(first+last-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


first = last = 1
primeFactor = prime_factorize(N)
primeFactor.reverse()

for x in primeFactor:
    if first*x <= N**0.5 :
        first *= x
    else :
        last *= x

print(first+last-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


first = last = 1
primeFactor = prime_factorize(N)
primeFactor.reverse()
print(primeFactor)

for x in primeFactor:
    if first*x <= N**0.5 :
        first *= x
    else :
        last *= x
print(first,last)
print(first+last-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


first = last = 1
primeFactor = prime_factorize(N)
primeFactor.reverse()

for i,x in enumerate(primeFactor):
    if first*x <= N**0.5 :
        first *= x
    else :
        last *= x

print(first+last-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


even = odd = 1
primeFactor = prime_factorize(N)

for i,x in enumerate(primeFactor):
    if i%2 == 0 :
        even *= x
    else:
        odd *= x

print((even-1) + ( odd-1))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
not_prime = [0, 2, 4, 5, 6, 8]
ans = 0

def isPrime(n):
    if n % 10 in not_prime:
        return False
    
    num_array = list(map(int, str(n)))
    if sum(num_array) % 3 == 0:
        return False
    
    for i in  range(3, int(math.sqrt(n)), 2):
        if(n % i == 0):
            return False
    return True

if math.sqrt(N).is_integer() :
    ans = (int(math.sqrt(N))-1)*2 
elif isPrime(N) :
    ans = N-1
else :
    ans = round(math.sqrt(N))*2-1

print(ans)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
not_prime = [0, 2, 4, 5, 6, 8]
ans = 0

def isPrime(n):
    if n % 10 in not_prime:
        return False
    
    num_array = list(map(int, str(n)))
    if sum(num_array) % 3 == 0:
        return False
    
    for i in  range(3, int(math.sqrt(n)), 2):
        if(n % i == 0):
            return False
    return True
 
if isPrime(N) :
    ans = N-1
elif math.sqrt(N).is_integer() :
    ans = (int(math.sqrt(N))-1)*2
else :
    ans = round(math.sqrt(N))*2-1

print(ans)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
not_prime = [0, 2, 4, 5, 6, 8]
ans = 0

def isPrime(n):
    if n % 10 in not_prime:
        return False
    
    num_array = list(map(int, str(n)))
    if sum(num_array) % 3 == 0:
        return False
    
    for i in  range(3, int(math.sqrt(n)), 2):
        if(n % i == 0):
            return False
    return True
 
if isPrime(N) :
    ans = N-1
elif math.sqrt(N).is_integer() :
    ans = int(math.sqrt(N))
else :
    ans = round(math.sqrt(N))*2-1

print(ans)

Submission status: Wrong Answer

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

not_prime = [0, 2, 4, 5, 6, 8]
def isPrime(n):
    if n % 10 in not_prime:
        return False
    
    num_array = list(map(int, str(n)))
    if sum(num_array) % 3 == 0:
        return False
    
    for i in  range(3, int(math.sqrt(n)), 2):
        if(n % i == 0):
            return False
    return True
 
ans = N-1 if isPrime(N) else round((N**0.5))*2 -1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

def prime(n):
    p_n = []
    for i in range(2,int(n ** (1/2))):
        while n % i == 0:
            p_n.append(i)
            n /= i
    if n != 1:
        p_n.append(int(n))
    return p_n

queue = prime(N)
queue.sort(reverse=True)
while len(queue) > 2:
    a,b = queue.pop(),queue.pop()
    queue.append(a*b)
    queue.sort(reverse=True)

if len(queue) == 1:
    print(sum(queue)-1)
else:
    print(sum(queue)-2)

Submission status: Wrong Answer

Solution code:
#nの約数列挙
def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            if i**2 == n:
                continue
            ass.append(n//i)
    ass.sort()
    return ass

n = int(input())

li = divisor(n)

ans = li[(len(li)//2)] + li[(len(li)//2)-1] - 2

print(ans)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
s = 0
if N % 2 == 0:
  s = 2 + N // 2

for i in range(3, math.ceil(math.sqrt(N)) + 3, 2):
  if N % i == 0 and (not s or s > i + N // i):
    s = i + N // i

if not s:
  s = N + 1

print(s-2)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
s = 0
if N % 2 == 0:
  s = 2 + N // 2

for i in range(3, math.ceil(math.sqrt(N)) + 3, 2):
  if N % i == 0 and (not s or s > i + N // i):
    s = i + N // i

print(s-2)

Submission status: Wrong Answer

Solution code:
n = int(input())

divs = {}
ans = float('inf')

for i in range(1,int(n**(1/2))):
    if n%i == 0:
        a = i
        b = n//i
        tmp = a+b-2
        if tmp < ans:
            ans = tmp
print (ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
#i+j-2=cnt & i*j=n
minn=n+2
i=1
while i**2<n:
    if n%i==0:
        j=n/i
        minn=min(int(i+j-2),minn)
    i+=1
print(minn)

Submission status: Wrong Answer

Solution code:
n=int(input())
#i+j-2=cnt & i*j=n
import math
minn=100000000000000000000
i=1
while i**2<n:
    if n%i==0:
        j=n/i
        minn=min(int(i+j-2),minn)
    i+=1
print(minn)

Submission status: Wrong Answer

Solution code:
n=int(input())
#i+j-2=cnt & i*j=n
import math
minn=100000000000000000000
for i in range(1,round(math.sqrt(n))):
    if n%i==0:
        j=n/i
        minn=min(int(i+j-2),minn)
    else:
        continue
print(minn)

Submission status: Wrong Answer

Solution code:
n=int(input())
#i+j-2=cnt & i*j=n
import math
minn=100000000000000
for i in range(1,math.floor(math.sqrt(n))):
    if n%i==0:
        j=n/i
        minn=min(int(i+j-2),int(minn))
    else:
        continue
print(minn)

Submission status: Wrong Answer

Solution code:
n=int(input())
#i+j-2=cnt & i*j=n
import math
minn=10000000000000000
for i in range(1,round(math.sqrt(n))):
    if n%i==0:
        j=n/i
        minn=min(int(i+j-2),int(minn))
    else:
        continue
print(minn)

Submission status: Wrong Answer

Solution code:
N = int(input())

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

ans = make_divisors(N)
result = []
if len(ans)%2 == 0:
    for i, j in zip(range(0, int(len(ans)/2)), reversed(range(int(len(ans)/2), len(ans)))):
        result.append(int(ans[i]+ans[j])-2)
else:
    result.append(ans[int(len(ans)/2)]-2)
print(min(result))

Submission status: Wrong Answer

Solution code:
N = int(input())

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

ans = make_divisors(N)
result = []
Min = float('inf')
for i, j in zip(range(0, int(len(ans)/2)), reversed(range(int(len(ans)/2), len(ans)))):
    result.append(ans[i]+ans[j]-2)
    
print(min(min(result), Min))

Submission status: Wrong Answer

Solution code:
N = int(input())

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

ans = make_divisors(N)
result = []
for i, j in zip(range(0, int(len(ans)/2)), reversed(range(int(len(ans)/2), len(ans)))):
    result.append(ans[i]+ans[j]-2)
    
print(min(result))

Submission status: Wrong Answer

Solution code:
N = int(input())

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

ans = make_divisors(N)
result = []
for i, j in zip(range(0, int(len(ans)/2)), reversed(range(int(len(ans)/2), len(ans)))):
    result.append((ans[i]-1)+(ans[j]-1))
    
print(min(result))

Submission status: Wrong Answer

Solution code:
N = int(input())

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

ans = make_divisors(N)
x = ans[int(len(ans)/2)-1]
y = ans[int(len(ans)/2)]

print((x-1)+(y-1))

Submission status: Wrong Answer

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

for i in range(1,n+1):
    if n % i == 0:
        a = i
        b = n/i
        if i == 1 or i == n:
            s = a + b - 2
        else:
            s = a + b - 1
        list.append(s)
print(int(min(list)))

Submission status: Wrong Answer

Solution code:
from math import sqrt
n=int(input())
def make_divisors(n):
	lower_divisors , upper_divisors = [], []
	i = 1
	while i*i <= n:
		if n % i == 0:
			lower_divisors.append(i)
			if i != n // i:
				upper_divisors.append(n//i)
		i += 1
	return lower_divisors + upper_divisors[::-1]
l=make_divisors(n)
if len(l)%2==0:
	print((l[len(l)//2]+l[(len(l)//2)-1])-2)
elif len(l)%2==1:
	print((sqrt(n)*2)-2)

Submission status: Wrong Answer

Solution code:
n=int(input())
def make_divisors(n):
	lower_divisors , upper_divisors = [], []
	i = 1
	while i*i <= n:
		if n % i == 0:
			lower_divisors.append(i)
			if i != n // i:
				upper_divisors.append(n//i)
		i += 1
	return lower_divisors + upper_divisors[::-1]
l=make_divisors(n)
if len(l)%2==0:
	print((l[len(l)//2]+l[(len(l)//2)-1])-2)
elif len(l)%2==1:
	print((l[len(l)//2-1]+l[(len(l)//2)+1])-2)

Submission status: Wrong Answer

Solution code:
from math import sqrt as r
from math import floor 
from itertools import combinations as C

N = int(input())
P = []

while N % 2 == 0:
    N //= 2
    P.append(2)

for i in range(3, floor(r(N)) + 1, 2):
    while N % i == 0:
        N //= i
        P.append(i)

if N != 1:
    P.append(N)
    N = 1

n, m = [], []

for p in P:
    if P.count(p) >= 2:
        n.append(p)
        m.append(p)
        P.remove(p)
        P.remove(p)

print("s")

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 10 ** 12
print(int(N ** 0.5) + 1)
for x1 in range(1, int(N ** 0.5) + 1):
    if N % x1 == 0:
        y1 = N // x1
        now = x1 + y1 - 2
        ans = min(ans, now)
print(ans)

Submission status: Wrong Answer

Solution code:
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

n = int(input())
yaku = make_divisors(n)

Min = float('inf')
for i in range(int(len(yaku)/2)):
    Min = min(Min, yaku[i]+yaku[-(i+1)])

print(Min-2)

Submission status: Wrong Answer

Solution code:
n = int(input())
diff_min = 100000000000
for a in range(1, n + 1):
    if n % a == 0:
        b = n // a
        diff = a + b - 2
        diff_min = min(diff_min, diff)
    if a * a > n:
        break
print(diff_min)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
diff_min = 100000000000
for a in range(1, math.floor(math.sqrt(n))):
    if n % a != 0:
        continue
    b = n // a
    diff = a + b - 2
    if diff < diff_min:
        diff_min = diff
print(diff_min)

Submission status: Wrong Answer

Solution code:
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
    
n=int(input())
lis=make_divisors(n)
#print(lis)
ans=float('inf')
l=len(lis)
for i in range(l//2):
    ans=min(ans,lis[i]+lis[-1*(i+1)]-2)
if l%2:
    ans=min(ans,lis[l//2])
print(ans)

Submission status: Wrong Answer

Solution code:
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
    
n=int(input())
lis=make_divisors(n)
#print(lis)
ans=float('inf')
l=len(lis)
for i in range(l//2):
    ans=min(ans,lis[i]+lis[-1*(i+1)]-2)
if l%2:
    ans=min(ans,lis[l//2+1])
print(ans)

Submission status: Wrong Answer

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

import bisect

N=int(input())
list1=divisor(N)
value1=(N**0.5)//1
num=bisect.bisect_left(list1,value1)

x=list1[num]
print(int(x+N/x-2))

Submission status: Wrong Answer

Solution code:
import math

def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n // i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


n = int(input())
divisors_list = make_divisors(n)
ans = []
n_sqrt = math.sqrt(n)
print(divisors_list)
if n_sqrt == int(n_sqrt):
    for i in range(len(divisors_list) // 2 + 1):
        move = divisors_list[i] + divisors_list[-1 - i] - 2
        ans.append(move)
else:
    for i in range(len(divisors_list) // 2):
        move = divisors_list[i] + divisors_list[-1 - i] - 2
        ans.append(move)
print(min(ans))

Submission status: Wrong Answer

Solution code:
def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n // i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


n = int(input())
divisors_list = make_divisors(n)
ans = []
for i in range(len(divisors_list) // 2):
    move = divisors_list[i] + divisors_list[-1 - i] - 2
    ans.append(move)
print(min(ans))

Submission status: Wrong Answer

Solution code:
ans=99999999999999
n=int(input())
if n==1:
  print (0)
if n==2:
  print (1)
if n==3:
  print (2)
else:
  for i in range(int(pow(n,0.5)),0,-1):
    if n%i==0:
      break
  print (i+n//i-2)

Submission status: Wrong Answer

Solution code:
n=int(input())
ro=n**0.5
# print( ro )

maxi=1
for i in range(2, int(ro)):
    if n%i==0:
        maxi=i

print( maxi-1+n//maxi-1)

Submission status: Wrong Answer

Solution code:
def resolve():
    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)
    min_pair = 10**19
    for i in divisors[:len(divisors)//2]:
        pair_i = n//i
        min_pair = min(min_pair, ((i-1)+(pair_i-1)))
    print(min_pair)
resolve()

Submission status: Wrong Answer

Solution code:
# ABC144 C - Walk on Multiplication Table
n = int(input())
m = n
for i in range(int(n**0.5)):
    for j in range(int(n**0.5),n):
        if i*j==n:
            m = min(i+j-2,m)
print(m)

Submission status: Wrong Answer

Solution code:
# ABC144 C - Walk on Multiplication Table
n = int(input())
m = n
for i in range(n):
    for j in range(n):
        if i*j==n:
            m = min(i+j-2,m)
print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())

n_hoge = int(N ** 0.5)
print

true_ans = 10 ** 12
for i in range(1,n_hoge):
    if N % i == 0:
        ans = N // i
        true_ans = min(ans + i - 2, true_ans)

print(true_ans)

Submission status: Wrong Answer

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

	i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
ans_l,ans_r=0,0
root = math.floor(math.sqrt(n))
for i in range(10**5):
    if n%root == 0:
        ans_l,ans_r = root,n//root
        break
    else:
        root -= 1
print(ans_l-1 + ans_r-1)

Submission status: Wrong Answer

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

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

div_list = make_divisors(n)
print(div_list)

mn =2**50
for i in div_list:
    mn = min(mn,i+n//i)

print(mn-2)

Submission status: Wrong Answer

Solution code:
def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors, upper_divisors


n = int(input())
low, up = make_divisors(n)
if up:
    print(low[-1] - 1 + up[-1] - 1)
else:
    print(n - 1)

Submission status: Wrong Answer

Solution code:
from sys import exit
import math

def main():
  N = int(input())
  ran = int(math.sqrt(N))
  ans = N
  
  for i in range(1,ran):
    if N % i == 0:
      if N / i + i <= ans + 1:
        ans = ((N / i) + i) -2
  
  print(int(ans))
  
  
  
main()

Submission status: Wrong Answer

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

for i in range(1,int(N**0.5)):
  if N%i == 0:
    ans = min([ans, i+N//i-2])
    
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
result=float('inf')
for i in range(1,int(n**.5)):
  if i*(n//i)==n:
    result=min(result,abs(i+n//i)-2)
print(result)

Submission status: Wrong Answer

Solution code:
import sys
import time
import math
import itertools as it
def inpl():
    return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------

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

ls = prime_factorize(N)
x, y = 1, 1
for i in range(len(ls)):
    if i % 2 == 0:
        x *= ls[i]
    else:
        y *= ls[i]
print(x+y-2) 


# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
ans = float("inf")
for i in range(1,n+1):
  for j in range(i,math.ceil(n**0.5)+3):
    if i*j == n:
      ans = min(ans,i+j-2)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0

for i in range(10**6):
    if i*i < n:
        continue
    elif i*i >= n:
        break

for j in range(i):
    if (i-j) * (i+j) == n:
        break

if (i-j) * (i+j) != n:
    for j in range(i):
        if (i-1-j) * (i+j) == n:
            ans = 2*i-3
            break
else:
    ans = 2*i-2

if ans == 0:
    ans = n-1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = []
for i in range(1,10**6):
    if n % i == 0:
        ans.append(i+(n//i)-2)

print(min(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = n
i = 1
while i*i<=n :
  if n%i == 0 :
    d = n/i
    if ans > i+d-2 : ans = i+d-2
  i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = n
i = 1
while i*i<=n :
  if n%i == 0 :
    d = n/i
    if ans > i*d-2 : ans = i+d-2
  i+=1
print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = n
i = 1
while i*i<=n :
  if n%i == 0 :
    d = n/i
    if ans > i*d-2 : ans = i+d-2
  i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = 0
res = n
for i in range(1, n+1):
  for j in range(1, n+1):
    if i*j != n :
      a += 1
      
    else:
      print(i, j, a)
      if res > a:
        res = a
        print('res: ',res)
      a = i
      print('reset a: ', a)
      break
print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

print(ans)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
p = 10 ** 12
m = math.floor(math.sqrt(n))

for i in range(1,m):
    if n % i == 0:
        j = n // i
        p = min(p,i-1+j-1)

print(p)

Submission status: Wrong Answer

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

han=999999999999999999999999999999999999999999
b=0



for a in range(1,int(math.sqrt(N))+1):
    if N%a==0:
        A=N/a
        if A>a:
            gou=A-a
        else:
            gou=a-A
        b=a
        if gou<han:
            han=gou
            kot=A+a
if b==A:
    print(int(kot)-1)
else:
    print(int(kot)-2)

Submission status: Wrong Answer

Solution code:
import math
N=944128792089

han=999999999999999999999999999999999999999999
b=0



for a in range(1,int(math.sqrt(N))+1):
    if N%a==0:
        A=N/a
        if A>a:
            gou=A-a
        else:
            gou=a-A
        b=a
        if gou<han:
            han=gou
            kot=A+a
if b==A:
    print(int(kot)-1)
else:
    print(int(kot)-2)

Submission status: Wrong Answer

Solution code:
import math
N=50
han=999999999999999999999999999999999999999999
b=0



for a in range(1,int(math.sqrt(N))+1):
    if N%a==0:
        A=N/a
        if A>a:
            gou=A-a
        else:
            gou=a-A
        b=a
        if gou<han:
            han=gou
            kot=A+a
if b==A:
    print(int(kot)-1)
else:
    print(int(kot)-2)

Submission status: Wrong Answer

Solution code:
import math
N=10000000019
han=999999999999999999999999999999999999999999
b=0



for a in range(1,int(math.sqrt(N))+1):
    if N%a==0:
        A=N/a
        if A>a:
            gou=A-a
        else:
            gou=a-A
        b=a
        if gou<han:
            han=gou
            kot=A+a
if b==A:
    print(int(kot)-1)
else:
    print(int(kot)-2)

Submission status: Wrong Answer

Solution code:
import math

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

Submission status: Wrong Answer

Solution code:
import math

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

Submission status: Wrong Answer

Solution code:
import math

N=int(input())
res=[N]
for i in range(1,int(math.sqrt(N))):
  for j in range(1,N):
    if(i*j==N):
      res.append(i+j-2)
print(min(res))

Submission status: Wrong Answer

Solution code:
import math
import sys

N=int(input())
res=[N]
j=1
for i in range(int(math.sqrt(N)),1,-1):
  for j in range(N,1,-1):
    if(i*j==N):
      print(i+j-2)
      sys.exit()