TnT/Multi_CodeNet4Repair huggingface dataset:
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):
# ABC144c
import math


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

    # map(int,input().split())
    n = int(input())
    ans = 10**12
    for i in range(n//2+1):
        for j in range(n//2+1):
            if(i*j == n):
                ans = min(ans, i+j)
    print(ans)


if __name__ == '__main__':
    main()

# ABC144c


def main():
    import sys
    import math
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

    # map(int,input().split())
    n = int(input())
    ans = 10**12
    for i in range(math.ceil(math.sqrt(n))+1, 0, -1):
        if n % i == 0:
            ans = min(ans, i+n//i)
    print(ans-2)


if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Accepted
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):
n=int(input())
m = int(sqrt(m))
for i in reversed(range(1, m)):
  if N%i==0:
    j = N//i
    print(i+j-2)

import math
n = int(input())
m = int(math.sqrt(n))
for i in reversed(range(1, m+1)):
  print(i)
  if n % i == 0:
    j =  n // i
    print(i+j-2)
    break

import math
n = int(input())
m = int(math.sqrt(n))
for i in reversed(range(1, m+1)):
  print(i)
  if n % i == 0:
    j =  n // i
    print(i+j-2)
    break

n=int(input())
m = int(sqrt(m))
for i in reversed(range(1, m)):
  if N % i == 0:
    j =  N // i
    print(i+j-2)
    break

import math
n = int(input())
m = int(math.sqrt(n))
for i in reversed(range(1, m+1)):
  if n % i == 0:
    j =  n // i
    print(i+j-2)
    break

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

Accepted
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):
n = int(input())
a = 0
b = 0

for i in range(1, n+1):
    if n%i = 0:
        if a == n/i:
            b = i
        else:
            a = i

print(a+b-2)

import sys
import math

n = int(input())
ans = 0

for i in range(int(math.sqrt(n)), 0, -1):
    if n%i is 0:
        ans = int(n/i + i - 2)
        break
if ans is not 0:
    print(ans)
else:
    print(n-1)

Verdicts: Runtime Error

Accepted
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):
n = int(input())
ans = float('inf')

for i in range(1, 10**8+1):
    q, m = divmod(n, i)
    if m == 0:
        ans = min(ans, q+i)

print(ans-2)


n = int(input())
ans = float('inf')

for i in range(1, 10**7+1):
    q, m = divmod(n, i)
    if m == 0:
        ans = min(ans, q+i)

print(ans-2)


n = int(input())
ans = float('inf')

for i in range(1, 10**6+1):
    q, m = divmod(n, i)
    if m == 0:
        ans = min(ans, q+i)

print(ans-2)


Verdicts: Time Limit Exceeded

Time Limit Exceeded

Accepted
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
N = int(input())
tmp = math.ceil(N**(1/2))
ans = N-1
for i in range(3,tmp+1):
    if N%i == 0:
        ans = min(ans,N//i+i)
        ans -= 2

print(ans)

N = int(input())

ans = N

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

Verdicts: Wrong Answer

Accepted
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
N = int(input())
    
for i in range(1, int(math.sqrt(N)+1) ):
    if  N % i == 0:
        print(int(i + N/i - 2))
        exit()


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

Verdicts: Wrong Answer

Accepted
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):
n = int(input())
tmp = 1
 
for i in range(1,10**10):
  if n//i == 0:
    if i <= n//i:
      tmp  = i
    else:
      break
  elif tmp == 1 and i >= n/i:
    break
    
      
print(tmp + (n//tmp) -2)

n = int(input())
tmp = 1

for i in range(1,10**10):
  if n//i == 0:
    if i <= n//i:
      tmp  = i
    else:
      break
      
print(tmp + (n//tmp) -2)

n = int(input())
tmp = 1
 
for i in range(1,10**10):
  if n%i == 0:
    if i <= n//i:
      tmp  = i
    else:
      break
  elif i >= n/i:
    break
      
print(tmp + (n//tmp) -2)

Verdicts: Wrong Answer

Wrong Answer

Accepted
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
N = int(input())
ans = N-1
n = math.sqrt(N)
n = int(n)+1
for i in range(1, n)
    if N%i==0:
        tmp = N//i
        ans = (tmp-1)+(i-1)

    
print(ans)
        


import math
N = int(input())
ans = N-1
n = math.sqrt(N)
n = int(n)+1
for i in range(1, n):
    if N%i==0:
        tmp = N//i
        ans = (tmp-1)+(i-1)

    
print(ans)
        


Verdicts: Runtime Error

Accepted
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):
n = int(input())
if n >= 2:
     nm = [2]
     for i in range(3, n + 1):
         for p in nm:
             if i % p == 0:
                 break
         else:
             nm.append(i+n//i-2)
print(max(nm))

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

N = int(input())
val = []
for a in range(int(N**0.5)+1):
  b, mod = divmod(N, a+1)
  if mod == 0:
    val.append( (a+1) + b - 2 )
print(min(val))

Verdicts: Wrong Answer

Wrong Answer

Accepted
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):
data = int(input())
ng_flag = False
min_value = 9999999
for i in range(1, data + 1):
    if data % i == 0:
        validation = i + data / i
        if validation < min_value:
            min_value = validation
print(int(min_value))

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

min_value = 1000000000000
data = int(input())
ng_flag = False
divisors_array = make_divisors(data)

if len(divisors_array) % 2 == 1:
    divisors_array.append(divisors_array[len(divisors_array)-1])
for i in range(0, len(divisors_array)):
    if(i % 2 == 0):
        first = divisors_array[i] -1 
        second = divisors_array[i+1] -1 
        if first + second < min_value:
            if i == 1:
                min_value = first + second
            else:
                min_value = first + second
print(min_value)

Verdicts: Wrong Answer

Accepted
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):
from numpy import sqrt
n = int(input())
q = int(sqrt(n)) + 1
for i in reversed(range(1,q)):
    if n%i == 0:
        print(n//i, i)
        print(n//i + i - 2)
        break


from numpy import sqrt
n = int(input())
q = int(sqrt(n)) + 1
for i in reversed(range(1,q)):
    if n%i == 0:
        print(n//i + i - 2)
        break


Verdicts: Wrong Answer

Accepted
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):
def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(n // i + i)
            if i != n // i:
                print(n // i, i)
                divisors.append(n // i + i)
    divisors.sort()
    return divisors


def main():
    n = int(input())
    divs = make_divisors(n)
    res = divs[0]

    print(res - 2)


if __name__ == '__main__':
    main()

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


def main():
    n = int(input())
    divs = make_divisors(n)
    res = divs[0]
    print(res - 2)


if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Accepted
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):
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)

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

Verdicts: Wrong Answer

Accepted
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

ans = 1000000000000000000
N = int(input())
for i in range(math.sqrt(N+1000)):
  if i > 0 and N % i == 0:
    ans = min(i + N/i - 2, ans)
print(ans)

import math

ans = 1000000000000000000
N = int(input())
for i in range(math.ceil(math.sqrt(N+1000))):
  if i > 0 and N % i == 0:
    ans = min(i + N/i - 2, ans)
print(int(ans))


Verdicts: Runtime Error

Accepted
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

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)


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)


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
        break
        
print(i+j-2)

Verdicts: Wrong Answer

Wrong Answer

Accepted
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
N=int(input())
dis=N-1

for i in range(2,int(math.sqrt(N))+1):
    if N%i==0:
        if ((N/i)-1)+(i-1)<dis:
            dis=((N/i)-1)+(i-1)
        else:
            pass
    else:
        pass
print(dis)
        
        


import math
N=int(input())
dis=N-1

for i in range(2,int(math.sqrt(N))+1):
    if N%i==0:
        if ((N/i)-1)+(i-1)<dis:
            dis=((N/i)-1)+(i-1)
        else:
            pass
    else:
        pass
print(int(dis))
        
        


Verdicts: Wrong Answer

Accepted
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
input=sys.stdin.readline

def main():
    n = int(input())
    for a in range(1,10**6+1):
        if n%a==0:
            b=n//a
        ans=a+b-2
    print(ans)

if __name__=="__main__":
    main()

import math

def dictcheck(dict):
    min = 0
    for k,v in dict.items():
        if k == 1:
            min = v
            break
        elif min == 0:
            min=(int(k)-1)+(int(v)-1)
        elif min > (int(k)-1)+(int(v)-1):
            min = (int(k)-1)+(int(v)-1)
        else:
            continue
    print(min)

def main():
    N = int(input())
    i = 2
    tmpdict= {}
    while i <= math.sqrt(N):
        if N % i == 0:
            tmpdata = {i:N/i}
            tmpdict.update(tmpdata)
            i+=1
        else:
            i+=1
    if len(tmpdict)==0:
        tmpdata = {1:N-1}
        tmpdict.update(tmpdata)
    print(tmpdict)
    dictcheck(tmpdict)

if __name__ == "__main__":
    main()

#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    n = int(input())
    ans=10**12
    tmp=[]
    for a in range(1,10**6+1):
        if n%a==0 and n >=a:
            b=n//a
        elif n <a:
            break
        
        ans=min(ans,a+b-2)
    print(ans)

if __name__=="__main__":
    main()

Verdicts: Wrong Answer

Wrong Answer

Accepted
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):
N = int(input())
count = 1+N
for i in range(1,N/2 +1):
  if N % i == 0 and i + N/i < count:
    count = i+ N/i
count = int(count)
print(count-2)


N = int(input())
count = 1+N
for i in range(1,int(N**0.5)+1):
  if N % i == 0 and i + N/i < count:
    count = i+ N/i
count = int(count)
print(count-2)


Verdicts: Runtime Error

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

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

Verdicts: Wrong Answer

Accepted
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
b = input()
a = int(b)

c = int(math.sqrt(a))

for i in range(10000000):
    d = a / (c + i)
    if d.is_integer() == True & i <= 1000:
        break
    if i > 1000:
        for j in range(1000000):
            f = a / (2 + j)
            if f.is_integer() == True:
                break
        break

if i > 1000:
    g = f + j
    print(int(g))
else:
    e = d + c + i - 2
    print(int(e))


import math
b = input()
a = int(b)

c = int(math.sqrt(a))

for i in range(1000):
    d = a / (c + i)
    if d.is_integer() == True:
        break

e = c + i

print(d + e - 2)

import math
b = input()
a = int(b)

sqA = int(math.sqrt(a))

for i in range(10000000):
    d = a / (sqA - i)
    if d.is_integer() == True:
        break


e = d + sqA - i - 2
print(d)
print(sqA + i)
print(int(e))


import math
b = input()
a = int(b)

sqA = int(math.sqrt(a))

for i in range(10000000):
    d = a / (sqA - i)
    if d.is_integer() == True:
        break


e = d + sqA - i - 2

print(int(e))


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
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):
n = int(input())

ans_min = n - 2
for a in range(1, int(n ** 0.5) + 1):
    b = n / a
    if b.is_integer():
        if a + b - 2 < ans_min:
            ans_min = a + b - 2
print(ans_min)


def main():
    N = int(input())
    for n in range(int(N ** (1 / 2)) + 1)[::-1]:
        if N % n == 0:
            print(n - 1 + N // n - 1)
            return
main()

Verdicts: Wrong Answer

Accepted
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):
n = int(input())
ans = 0
for i in range(int(n**0.5)):
  if n%i == 0:
    l = i + (n/i) -2 
    ans = min(ans, l)
print(ans)



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




Verdicts: Runtime Error

Accepted
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):
N = float(input())
A = int(N**(0.5))
max = 10**12
print(A)
for i in range(1,A+1):
    B = N/float(i)
    if B.is_integer():
        c = i+B-2
        if c<= max:
            max = c
print(int(max))

N = float(input())
A = int(N**(0.5))
max = 10**12
for i in range(1,A+1):
    B = N/float(i)
    if B.is_integer():
        c = i+B-2
        if c<= max:
            max = c
print(int(max))

Verdicts: Wrong Answer

Accepted
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):
N=int(input())
n = N**0.5

if n % 1 == 0:
  print(2* n -2)
else:
  n = int(round(n, 0))
  while N % n != 0 :
    n = n - 1
  b = N / n
  print(n + b -2)

import math

N=int(input())
n = N**0.5

if n % 1 == 0:
  print(math.floor(2* n -2))
else:
  n = int(round(n, 0))
  while N % n != 0 :
    n = n - 1
  b = N / n
  print(math.floor(n + b -2))

Verdicts: Wrong Answer

Accepted
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
N = int(input())
M = int(math.sqrt(N))
for i in range(M, 0, -1):
    if N % M == 0:
        A = N // M
    	print(A + M - 2)
    	break

import math
N = int(input())
M=int(math.sqrt(N))
for i in range(M,0,-1):
	if N%M==0:
    	A=N//M
      	print(A+M-2)
      	break

import math
N = int(input())
M = int(math.sqrt(N))
for i in range(M, 0, -1):
    if N % M == 0:
        A = N / M
    	print(A + M - 2)
    	break

import math
N = int(input())
M=int(math.sqrt(N))
for i in range(M,0,-1):
	if N%M==0:
      A=N//M
      print(A+M-2)
      break

import math
N = int(input())
M = int(math.sqrt(N))
for i in range(M, 0, -1):
    if N % i == 0:
        A = N / i
        print(int(A + i - 2))
        break

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
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
n = int(input())
for i in range(math.floor(math.sqrt(n)), 0, -1):
    if n % i==0:
        print(i + n/i - 2)
        exit()

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

Verdicts: Wrong Answer

Accepted
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
N=int(input())
for i in reversed(range(int(math.sqrt(N)))):
    if N%(i+1)==0:
        print(N//(i+1)+i+1)
        break

import math
N=int(input())
for i in reversed(range(int(math.sqrt(N)))):
    if N%(i+1)==0:
        print(N//(i+1)+i+1-2)
        break

Verdicts: Wrong Answer

Accepted
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):
N=int(input())

li=[]
for i in range(1,int(N**0.5)+1):
  if N%i==0:
    li.append(i+N//i)
print(min(li))

N=int(input())

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

Verdicts: Wrong Answer

Accepted
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
n = int(input())

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

import math
n = int(input())

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

Verdicts: Wrong Answer

Accepted
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
N = int(input())
ans = 10000000020
for i in range(1,int(math.sqrt(N)+1)):
    if i * i > N:
        break
    if N % i != 0:
        continue
    j = N / i
    ans = min(ans, i+j-2)

print(ans)


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

print(ans)


import math

N = int(input())

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



Verdicts: Wrong Answer

Wrong Answer

Accepted
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):
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")


from math import sqrt as r
from math import floor

N = int(input())

ans = 10 ** 20

for i in range(1, floor(r(N)) + 1, 1):
    if N % i == 0:
        a = i - 1
        b = (N // i) - 1
        ans_ = a + b
        ans = min(ans, ans_)

print(ans)


Verdicts: Wrong Answer

Accepted
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):
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 = int(input())
ls = prime_factorize(n)

for i in range(len(ls) //2 + 1):
  ans = []
  ans.append(i + n / i - 2)

ans.sort()
print(ans[0])



def prime_factorize(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())
ls = prime_factorize(n)
for i in range(len(ls)):
  ans = []
  pair = n // ls[i]
  ans.append(ls[i] + n // ls[i] - 2)
 
ans.sort()
print(ans[0])

Verdicts: Runtime Error

Accepted
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):
n = int(input())
stop = int(sqrt(n)) + 1
min_count = 10 ** 100
for a in range(1, stop):
    if n % a != 0:
        continue
    else:
        b = n // a
    count = a + b - 2
    if count < min_count:
        min_count = count
print(min_count)

n = int(input())
stop = int(sqrt(n)) + 1
min_count = 10 ** 100
for a in range(1, stop):
    if n % a != 0:
        continue
    else:
        b = n // a
    count = a + b - 2
    if count < min_count:
        min_count = count
print(min_count)

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

Verdicts: Runtime Error

Runtime Error

Accepted
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
a,b,x =map(int,input().split( ))
if x >= (a**2*b/2):
    k=2*x/(a**2)-b
    cos=math.sqrt((b-k)**2/((a**2)+(b-k)**2))
    print(90-math.degrees(math.acos(cos)))
else:
    k=2*x/(a*b)
    cos=math.sqrt(b**2/(b**2+k**2))
    print(90-math.degrees(math.acos(cos)))

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

Verdicts: Runtime Error

Accepted
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

N = int(input())

ans = 10**13


for i in range(1,10**6+1:
    if N % i == 0:
        j = N / i
        ans = min(ans,j + i - 2)
        
print(int(ans))

import math

N = int(input())

ans = 10**13


for i in range(1,10**6+1):
    if N % i == 0:
        j = N / i
        ans = min(ans,j + i - 2)
        
print(int(ans))

Verdicts: Runtime Error

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

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

Verdicts: Wrong Answer

Accepted
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):
from math import sqrt
n=input()
for i in range(sqrt(n),0,-1):
  if n%i==0:
    j=n//i
    pirnt(i+j-2)
    break

n=input()
for i in range(sqrt(n),0,-1):
  if n%i==0:
    j=n//i
    pirnt(i+j-2)
    break

from math import sqrt

N=int(input())
for i in range(int(sqrt(N)),0,-1):
    if N % i == 0:
        j=N//i
        pirnt(i+j-2)
        break


from math import sqrt
n=int(input())
for i in range(int(sqrt(n)),0,-1):
  if n%i==0:
    j=n//i
    pirnt(i+j-2)
    break

from math import sqrt
n=int(input())
for i in range(int(sqrt(n)),0,-1):
  if n%i==0:
    j=n/i
    pirnt(i+j-2)
    break


from math import sqrt

N=int(input())
for i in range(int(sqrt(N)),0,-1):
  if N%i==0:
    j=N//i
    pirnt(i+j-2)
    break


from math import sqrt
n=int(input())
for i in range(int(sqrt(n)),0,-1):
  if n%i==0:
    j=n//i
    pirnt(i+j-2)
    break

n=inupt()
for i in range(sqrt(n),0,-1):
  if n%i==0:
    j=n//i
    pirnt(i+j-2)
    break

from math import sqrt
n=int(input())
for i in range(sqrt(n),0,-1):
  if n%i==0:
    j=n//i
    pirnt(i+j-2)
    break

from math import sqrt
n=int(input())
for i in range(int(sqrt(n)),0,-1):
  if n%i==0:
    j=n//i
    pirnt(i+j-2)
    break

from math import sqrt

N = int(input())
for i in range(int(sqrt(N)), 0, -1):
    if N % i == 0:
        j = N // i
        print(i + j - 2)
        break


Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
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):
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 = int(input())
A = prime_factorize(N)
A.append(1)

while len(A) > 2:
    A[0] = A[0] * A[1]
    del A[1]
    A.sort()
print(A[0]+A[1]-2)

import numpy as np

N = int(input())

U = 10**6 + 100
x = np.arange(1,U, dtype=np.int64)
div = x[N%x==0]
ans = (div + N//div).min() - 2
print(ans)

Verdicts: Wrong Answer

Accepted
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):
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)

N = int(input())
ans = 10 ** 12
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)

Verdicts: Wrong Answer

Accepted
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):
n = int(input())
m = 10**13
for x in range(1,1000001):
  y = n / x
  if y % 1 == 0:
    v = x + y -2
    m = min(m, v)
print(m)

n = int(input())
m = 10**13
for x in range(1,1000001):
  y = n / x
  if y % 1 == 0:
    v = x + y -2
    m = min(m, v)
print(int(m))

Verdicts: Wrong Answer

Accepted
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):
a=int(input())
for x in range(int(a**0.5),0,-1):
	if a%x==0:
    d=int(a//x)
    break
print(d+x-2)


a=int(input())
for x in range(int(a**0.5),0,-1):
	if a%x==0:
    d=int(a//x)
    s=d+x-2
    break
print(s)


a=int(input())
for x in range(int(a**0.5),0,-1):
	if a%x==0:
    d=a//x
    s=d+x-2
    break
print(s)

a=int(input())
for x in range(a**0.5,0,-1)
	if a%x==0:
    s=a+x-2
    break
print(s)

a=int(input())
for x in range(int(a**0.5),0,-1)
	if a%x==0:
    d==a//x
    s==d+x-2
    break
print(s)

a=int(input())
for x in range(int(a**0.5),0,-1):
  if a%x==0:
    b=int(a//x)
    break
print(b+x-2)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
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):
N = int(input())

Abs = int(np.sqrt(N))
if Abs ** 2 == N:
    print((Abs - 1) * 2)
else:
    min = N + 1
    min_i = 0
    for i in range(1, Abs + 1):
        tmp = N // i
        if tmp * i == N:
            if min > tmp:
                min = tmp
                min_i = i

print(min + min_i - 2)

import numpy as np
N = int(input())
Abs = int(np.sqrt(N))
if Abs ** 2 == N:
    print(Abs + Abs - 2)
else:
    min = N + 1
    min_i = 1
    for i in range(1, Abs + 1):
        tmp = N // i
        if tmp * i == N:
            if min > tmp:
                min = tmp
                min_i = i
    print(min + min_i - 2)

Verdicts: Runtime Error

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

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

Verdicts: Runtime Error

Accepted
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):
N=int(input())
ans=[]
for i in range(1,N**.5):
    if N%i==0:
        ans.append(N//i+i-2)
print(min(ans))

N=int(input())
ans=[]
for i in range(1,int(N**.5)+2):
    if N%i<1:
        ans.append(N//i+i-2)
print(min(ans))

Verdicts: Runtime Error

Accepted
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):
n = int(input())
min = n+1
kaisu = int((n/4)-1)

for i in range(kaisu):
    if n%(i+1)==0:
        tmp = i+(n/(i+1))-1
        if min > tmp:
            min = tmp
    if (i+1)**2>n:
        break

print(int(min))

n = int(input())
min = n+1
kaisu = int(n-1)
if 
for i in range(kaisu):
    if n%(i+1)==0:
        tmp = i+(n/(i+1))-1
        if min > tmp:
            min = tmp
    if (i+1)**2>n:
        break

print(int(min))

n = int(input())
min = n+1
kaisu = int(n-1)

for i in range(kaisu):
    if n%(i+1)==0:
        tmp = i+(n/(i+1))-1
        if min > tmp:
            min = tmp
    if (i+1)**2>n:
        break

print(int(min))

Verdicts: Wrong Answer

Runtime Error

Accepted
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):
n=int(input())
i=1
ans=10**13
while(i*i<=n):
    if(n%i==0):
        ans=min(ans,n/i+i-2)
    i+=1
print(ans)

n=int(input())
i=1
ans=10**13
while(i*i<=n):
    if(n%i==0):
        ans=min(ans,n//i+i-2)
    i+=1
print(ans)

Verdicts: Wrong Answer

Accepted
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):
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)

    
    return divisors

d = make_divisors(N)
# print(d)

Ans_min = 1+N-2

for x in d:
  y = N/x
  Ans = x+y-2
  if Ans < Ans_min:
    Ans_min = Ans
    
print(Ans_min)


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)

    
    return divisors

d = make_divisors(N)
# print(d)

Ans_min = 1+N-2

for x in d:
  y = N/x
  Ans = x+y-2
  if Ans < Ans_min:
    Ans_min = Ans
    
print(int(Ans_min))


Verdicts: Wrong Answer

Accepted
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):
n = int(input())
x = 1
res = n
while x * x <= n:
  if n % x == 0:
    res = min(res, x + n // x)
    x += 1
print(res)

n = int(input())
int x = 1
res = n
while x * x <= n:
  if n % x == 0:
    res = min(res, x + n // x)
print(res)

n = int(input())
x = 1
res = n
while x * x <= n:
  if n % x == 0:
    res = min(res, x + n // x)
print(res)

n = int(input())
i = 1
res = n
while i * i <= n:
  if n % i == 0:
    res = min(res, i + n//i - 2)
  i += 1
print(res)

Verdicts: Wrong Answer

Runtime Error

Time Limit Exceeded

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

from math import sqrt
n=int(input())
N=int(sqrt(n))
ans=n-1
for i in range(2,N):
  if n%i==0:
    if ans>n/i+i-2:
      ans=n/i+i-2
print(ans)

n= int(input())
import math
INF = 10**12
ans =INF
for i in range(math.floor(n**0.5)):
  if n%(i+1)==0:
    if ans > (i+1)+(n/(i+1)):
      ans = (i+1)+(n/(i+1))
print(int(ans-2))

Verdicts: Wrong Answer

Wrong Answer

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

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

Verdicts: Wrong Answer

Accepted
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):
N = int(input())
root = int(N**0.5)
for i in range(root,1,-1):
  if N % i ==0:
    break

print(N/i + i -2)


N = int(input())
root = int(N**0.5)
for i in range(root,-1,-1):
  if N % i ==0:
    break

print(int(N/i + i -2))


Verdicts: Runtime Error

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

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


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


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


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
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):
def prime_factor(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

N = int(input())

table = prime_factor(N)
table.sort()

tmp1 = 1
tmp2 = N  

for i in range(len(table)):
    tmp1 *= table[i]
    tmp2 /= table[i]

    if tmp1 >= tmp2:
        break
    
print(tmp1 + int(tmp2) - 2)

import math

N = int(input())

res = 10 ** 15
for i in range(1, int(math.sqrt(N))+1):
    if N%i == 0:
        res = min(res, N // i + i)

print(res-2)



Verdicts: Wrong Answer

Accepted