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):
a=int(input())
for i in range(a):
    if a%(i+1)==0:
        p=a//(i+1)
        if a>=p:
            break
print(i+p-1)

n=int(input())
i=0
s=[]
p=0
for i in range(n):
    i+=1
    if i<10 and p==0:
        print(n-1)
        quit()
        break
    if n%i==0:
        p=1
        s.append(n//i+i-2)
print(min(s))

a=int(input())
for i in range(a):
    p=a/(i+1)
    if (i+1)>=p and p%1==0:
        break
print(i+p-1)

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

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):
#ABC144_C

import math

init_N=int(input())
N=init_N
ans_list=[]
A=1
B=1

for i in range(2,int(math.sqrt(init_N))+1):
    while 1:  
        cnt+=1
        if N%i==0:
            ans_list.append(i)
            N=N//i
        else:
            break
if N==1:
    pass
else:
    ans_list.append(N)

if len(ans_list)==1:
    print(str(init_N-1))
else:
    while len(ans_list)>0:
        A=A*ans_list.pop(0)
        print(A)
        if len(ans_list)!=0:
            B=B*ans_list.pop(0)
            print(B)
    print(str(A+B-2))



import math

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

minimum=n-1
for i in range(1,n2+1):
    if(n%i==0):
        minimum=min(minimum,(n//i-1)+(i-1))

print(minimum)

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

a = int(input())
s = int(a ** 0.5)
for i in range(s):
  if a%(s-i)==0:
    print(int(a/(s-i) + (s-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):
# coding: utf-8
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

a=prime_factorize(n)
print(a)
m=len(a)
print(m)

b=1
c=1

if(m == 1):
    b=a[0]
elif(m == 2):
    b=a[0]
    c=a[1]
elif(m == 3):
    b=a[0]*a[2]
    c=a[1]
elif(m == 4):
    b=a[0]*a[3]
    c=a[1]*a[2]
elif(m == 5):
    b=a[0]*a[4]
    c=a[1]*a[2]*a[3]
elif(m == 6):
    b=a[0]*a[5]*a[2]
    c=a[1]*a[4]*a[3]
elif(m == 7):
    b=a[0]*a[6]*a[2]*a[4]
    c=a[1]*a[6]*a[3]
# 2 2 2 2 3 5 =240
elif(m % 4 == 0):
    for i in range(0,int(m/2),2):
        b=a[i]*a[m-1-i]
        c=a[i+1]*a[m-2-i]
elif(m % 4 == 1):
    for i in range(0,int(m/2),2):
        b=a[i]*a[m-1-i]
        c=a[i+1]*a[m-2-i]
    c=c*a[int(m/2) + 1]
elif(m % 4 == 2):
    for i in range(0,int(m/2),2):
        b=a[i]*a[m-1-i]
        c=a[i+1]*a[m-2-i]
    b=b/a[int(m/2) + 2]
    c=c*a[int(m/2) + 2]
elif(m % 4 == 3):
    for i in range(0,int(m/2),2):
        b=a[i]*a[m-1-i]
        c=a[i+1]*a[m-2-i]
    c=c/a[int(m/2) + 3]
print (b+c-2)


import math
n=int(input())

d=1e12
for i in range(1,int(math.sqrt(n))+1):
    if(n % i == 0):
        m=n/i + i- 2;
        if(m < d):
            d=m
print(d)


import math
n=int(input())

d=1e12
for i in range(1,int(math.sqrt(n))+1):
    if(n % i == 0):
        m=n/i + i- 2;
        if(m < d):
            d=m
print(int(d))


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

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)

    result = sorted(divisors)
    if len(result) == 2:
        final_i = result[0]
        final_j = result[1]
    else:
        if len(result)%2 == 0:
            final_i = result[len(result)//2]
            final_j = result[len(result)//2 - 1]
            
        else:
            final_i = result[(len(result)+1)//2]
            final_j = result[(len(result)+1)//2]
                 
    return final_i+final_j - 2

make_divisors(N)

# alone
N = int(input())
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)

result = sorted(divisors)
#print(result)

if len(result) == 2:
    final_i = result[0]
    final_j = result[1]
else:
    #print(len(result))
    if len(result)%2 == 0:
        final_i = result[len(result)//2 - 1]
        final_j = result[len(result)//2 ]
            
    else:
        final_i = result[(len(result))//2]
        final_j = result[(len(result))//2]
            
#print(final_i,final_j)        
print(final_i+final_j - 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 fractions
A = int(input())
for i in range(2,A+1):
  a = fractions.gcd(A,i)
  b = A/a
  break
print(int(i + b -2))
    

import fractions
A = int(input())
for i in range(2,A):
  a = fractions.gcd(A,i)
  b = A/a
  break
print(int(i + b -2))
    

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

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):
import itertools
import math
n = int(input())
lis1 = []
for i in range(n):
    lis1.append(list(map(int, input().split())))
S = 0
for i in list(itertools.permutations(range(n))):
#     print(i, type(i))
    for j in range(n-1):
#         print(lis1[i[j]][0], lis1[i[j+1]][0])
        S += math.sqrt((lis1[i[j]][0]-lis1[i[j+1]][0])**2 + (lis1[i[j]][1]-lis1[i[j+1]][1])**2)
for i in range(1, n+1):
    S = S / i
print(S)

n = int(input())
lis = []
for i in range(n):
    lis.append(list(map(int, input().split())))
s = 0
for i in range(n):
    for j in range(i,n):
        s += ((lis[i][0] - lis[j][0])**2 + (lis[i][1] - lis[j][1])**2)**(1/2)
print(s*2/n)

import itertools
import math
n = int(input())
lis1 = []
for i in range(n):
    lis1.append(list(map(int, input().split())))
S = 0
for i in list(itertools.permutations(range(n))):
    for j in range(n-1):
        S += math.sqrt((lis1[i[j]][0]-lis1[i[j+1]][0])**2 + (lis1[i[j]][1]-lis1[i[j+1]][1])**2)
for i in range(1, n+1):
    S = S / i
print(S)

n = int(input())
ans = float('inf')
for i in range(1, int(n**(1/2))+1):
    a, b = divmod(n, i)
    if b == 0:
        ans = min(ans, a+i-2)
print(ans)

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

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

for i in range(1, 1000000):
    if (N / i).is_integer():
        a = N // i
        b = N // a
        break

print(a+b-2)

N = int(input())

for i in range(int(N**0.5), 0, -1):
    if (N / i).is_integer():
        a = N // i
        b = N // a
        break

print(a+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


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


if(__name__ == "__main__"):
    main()


import math


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


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


import math
N=int(input())
rN=math.ceil(math.sqrt(N))
for i in range(rN,0,-1):
  if N//i == N/i:
    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())

a = []
m = math.floor(a**(1/2))
for i in range(1,m + 1):
    if n % i == 0:
        a.append(i + (n/i) - 2)

print(int(min(a)))


import math
n = int(input())

a = []
m = amth.floor(a**(1/2))
for i in range(1,m + 1):
    if n % i == 0:
        a.append(i + (n/i) - 2)

print(int(min(a)))


import math
n = int(input())

m = math.floor(math.sqrt(n))
ans = n-1
for i in range(1,m+1):
    if n % i == 0:
        j = n // i
        ans = min(ans,i + j - 2)


print(ans)

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

ans_lis = []
for i in range(1,10**6):
    if N%i==0:
        ans_lis.appe
        nd(i+(N//i))
print(min(ans_lis)-2)


N = int(input())

ans_lis = []
for i in range(1,10**7):
    if N%i==0:
        ans_lis.append(i+(N//i))
print(min(ans_lis)-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())
if N**(1/2) >= 2:
  for x in range(int(N**(1/2)), 1, -1):
    if (N % x == 0):
      print(int(x + N/x - 2))
      break
  print(N-1)
else:
  print(N-1)

def prime_factors(n):
    i = 2
    factors = 1
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors = i
    if n > 1:
        factors = i
    return factors
N = int(input())
large_factor = prime_factor(N)
print(large_factor+(N/large_factor)-2)

def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors
N = int(input())
factors = prime_factors(N)
print(factors)
a, b = 1, 1
for elem in factors:
  if elem > a and elem > b:
    a *= b
    b = elem
  else:
    if a <= b:
      a *= elem
    else:
      b *= elem
print(a+b-2)

def prime_factors(n):
    i = 2
    factors = 1
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors = i
    if n > 1:
        factors = i
    return factors
N = int(input())
large_factor = prime_factors(N)
print(large_factor+(N/large_factor)-2)

def prime_factors(n):
    i = 2
    factors = 1
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors = i
    if n > 1:
        factors = i
    return factors
N = int(input())
large_factor = prime_factors(N)
print(int(large_factor+(N/large_factor)-2))

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

N = int(input)

N = int(input())
def findSteps(n):
  for x in range(int(n**(1/2)), 1, -1):
    if (n % x == 0):
      return (int(x + n/x - 2))
  return (N-1)
 
print(findSteps(N))

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

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

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


n = int(input()) 

import math

def is_prime(n):
  for k in range(int(math.sqrt(n)) + 1,0,-1):
    if n % k == 0:
      print(int(k-1+n/k-1))
      break


is_prime(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
n = int(input())
m = int(math.sqrt(n))

ans = n - 1

for a in range(m):
  if n % a == 0:
    b = n // a
    ans = min(ans, a + b - 2)
    
print(ans)

import math
n = int(input())
m = int(math.sqrt(n)) + 1

ans = n - 1

for a in range(2, m):
  if n % a == 0:
    ans = min(ans, a + n//a - 2)
    
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())
num_list = [(i-1) + (N//i-1) for i in range(1, int(N**(1//2))+1) if N%i == 0]
print(min(num_list))

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

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())
min_total = 100000000000000
for a in range(1, N // 2 + 2):
    b = N / a
    if b.is_integer():
        tmp_a_and_b = a + b
        if tmp_a_and_b < min_total:
            min_total = tmp_a_and_b

print(min_total - 2)



import math

N = int(input())

mi = -1

for i in range(1, int(math.sqrt(N)) + 1):
    a = i
    if N % a != 0:
        continue

    b = N // a
    count = a + b - 2
    
    if mi <= -1 or mi > count:
        mi = count

print(mi)





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 sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

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

def main():
  n = ni()

  x = divi(n)
  
  ans = 1e18+7
  for i in range(0, len(x), 2):
    print(x[i])
    ans = min(ans, x[i] - 1 + x[i+1] - 1)
  print(ans)
  

main()

import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

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

def main():
  n = ni()

  x = divi(n)
  
  ans = 1e18+7
  for i in range(0, len(x), 2):
    # print(x[i])
    try:
      ans = min(ans, x[i] - 1 + x[i+1] - 1)
    except:
      ans = min(ans, (x[i] - 1) * 2)  
  print(ans)
  
main()

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

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)
    a.sort(reverse = True)
    return a

a = prime_factorize(n = N)
print(sum(a) + 1)

N = int(input())
l = []
for i in range(1, 1000001):
    a = N / i
    if a.is_integer():
        l.append(i + N / i)
print(int(min(l) - 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())
i = 2
ans = n - 1
while i < n:
  if i * i > n:
    break
  if n % i > 0:
    continue
  j = n // i
  ans = min(ans, i + j - 2)
  i += 1
print(ans)

n = int(input())
i = 2
ans = n - 1
while i < n:
  if i * i > n:
    i += 1
    break
  if n % i > 0:
    continue
  j = n // i
  ans = min(ans, i + j - 2)
  i += 1
print(ans)

n = int(input())
i = 2
ans = n - 1
while i < n:
  if i * i > n:
    i += 1
    break
  if n % i > 0:
    i += 1
    continue
  j = n // i
  ans = min(ans, i + j - 2)
  i += 1
print(ans)

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 functools
import operator


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)
    if len(a) == 1:
        a.append(1)
    return a


N = int(input())
min_ans = 10 ** 12
prime_list = prime_factorize(N)
left_val = prime_list[0]
prod = functools.partial(functools.reduce, operator.mul)
right_val = prod(prime_list) / left_val
for i in range(1, len(prime_list)):
    min_ans = min(min_ans, left_val + right_val - 2)
    left_val *= prime_list[i]
    right_val /= prime_list[i]

print(min_ans)

import math

N = int(input())
min_ans = N

for a in range(1, int(N ** 0.5) + 1):
    if N % a != 0:
        continue
    b = N // a
    min_ans = min(min_ans, a + b - 2)

print(int(min_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):
dN = int(input())
yaku = 1

import math

    



if N % 2 == 0:
	yaku = 2
	
for i in range(3,int(math.sqrt(N))+1 ,1):
	if N % i == 0:
		yaku = i
		
		
yaku2 = int(N/yaku)

print(int(yaku2+yaku - 2))


N = int(input())
yaku = 1
import math

if N % 2 == 0:
	yaku = 2
	
for i in range(3,int(math.sqrt(N))+1 ,1):
	if N % i == 0:
		yaku = i
		
		
yaku2 = int(N/yaku)

print(int(yaku2+yaku - 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())
l=[]
for i in range(1,n**(1/2)//1+1):
  if n%i==0:
    l.append(n//i+i)
  if len(l)==3:break
print(min(l)-2)

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

n = int(input())
ans = n
for i in range(0,int(n**0.5)):
  if n % i == 0:
    j = target // i
    if (i+j-2) < ans:
      ans = i+j-2
print(ans)

target = int(input())
possibleAns = []

for i in range(1,10):
  for j in range(1,10):
    if i*j == taget:
		possibleAns.append(i+j)
print(min(possibleAns))


target = int(input())
curAns = target

for i in range(1,target**0.5):
  if target % i == 0:
    j = target // i
    if (i+j-2) < curAns:
      curAns = i+j-2
print(curAns)

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


target = int(input())
curAns = target

for i in range(1,target**0.5):
  if target % i == 0:
    j = target // i
    if (i+j-2) < curAns:
      curAns = i+j-2
print(curAns)


import math
target = int(input())
curAns = target

for i in range(0,int(math.sqrt(target))):
  if target % i == 0:
    j = target // i
    if (i+j-2) < curAns:
      curAns = i+j-2
print(curAns)

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

target = int(input())
possibleAns = []
 
for i in range(1,10):
  for j in range(1,10):
    if i*j == target:
		possibleAns.append(i+j)
print(min(possibleAns))

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

Verdicts: 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):
N = int(input())
from math import sqrt
res = set()
for i in range(int(sqrt(N)+1),0,-1):
  if N%i==0:
    print(i)
    res |= {N//i+i-2}
print(min(res))  

N = int(input())
from math import sqrt
res = set()
for i in range(int(sqrt(N)+1),0,-1):
  if N%i==0:
    res |= {N//i+i-2}
print(min(res))  


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

N = int(input())
for i in range(1,int(N**0.5+1)):
  if N % i == 0:
    ans = i + N // i - 2
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):
import math
ans = 10**12
n = int(input())
for a in range(1,int(math.sqrt(n)):
  for b in range(1,int(math.sqrt(n)):
    if a * b == n:
      ans_n = a + b -2
      if ans > ans_n:
        ans = ans_n
print(ans) 

import math
ans = 10**12
n = int(input())
for a in range(1,int(math.sqrt(N)):
  for b in range(1,int(math.sqrt(N)):
    if a * b == n:
      ans_n = a + b -2
      if ans > ans_n:
        ans = ans_n
print(ans) 

ans = 10**12
n = int(input())
for a in range(1,int(math.sqrt(N)):
  for b in range(1,int(math.sqrt(N)):
    if a * b == n:
      ans_n = a + b -2
      if ans > ans_n:
        ans = ans_n
print(ans) 

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: 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())
min = n
for i in range(1,n+1):
  if n % i == 0:
      if min < x + n/i
      
print(min)

n = int(input())
min = -1
for i in range(1,n+1):
  if min == -1:
    if n % i == 0:
      if min < x + n/i
      
print(min)

import math
n = int(input())
min = n - 1

split = n / math.sqrt(n)


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

print(int(min))

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
N=int(input())
a=int(math.sqrt(N))
while a>0:
  if N%a==0:
    print(a+N%a-2)
    break
  a-=1


import math
N=int(input())
a=int(math.sqrt(N))
while a>0:
  if N%a==0:
    print(a+N//a-2)
    break
  a-=1


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())
b = n**0.5//1.0
while True:
    if N%b != 0:
        b -= 1
    else:
        break
print(int(b+N/b-2))


N = int(input())
b = N**0.5//1.0
while True:
    if N%b != 0:
        b -= 1
    else:
        break
print(int(b+N/b-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):
import numpy as np

m = np.array(int(input()))

a = 1
b = m



#         a = int(i)
#         b = int(n / i)
#         break

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

soin = prime_factorize(n)

soin_r = soin[::-1]

tmp = 1
for i in range(len(soin) // 2):
    tmp *= soin[i]

zan = m / tmp

print(int(tmp + zan - 2))

"""
10
5

50
13

10000000019
10000000018

"""

import numpy as np

n = int(input())

a = 1
b = n

ans = n - 1

for i in range(2, int(np.sqrt(n) + 1)):
    if n % i ==  0:
        a = int(i)
        b = int(n / i)
        ans = min(ans, int(a + b - 2))

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):
import os

def main():
	n = int(input())
	list_a = make_divisors(n)
	min_num = 1000000000000
	print(list_a)
	for i in range(0,len(list_a),2):
		if n//list_a[i] == list_a[i]:
			min_num = list_a[i] * 2 - 2
			break
		if min_num < (list_a[i] + list_a[i+1] - 2):
			pass
		else:
			min_num = list_a[i] + list_a[i+1] - 2
	print(min_num)
	
			


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

	
if __name__ == "__main__":
	main()


import os

def main():
	n = int(input())
	list_a = make_divisors(n)
	min_num = 1000000000000
	for i in range(0,len(list_a),2):
		if n//list_a[i] == list_a[i]:
			min_num = list_a[i] * 2 - 2
			break
		if min_num < (list_a[i] + list_a[i+1] - 2):
			pass
		else:
			min_num = list_a[i] + list_a[i+1] - 2
	print(min_num)
	
			


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

	
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())
r=n**(1/2)
w=0
for i in range(1,int(r)+1):
  if n%i==0:
    w=i
x,y=w,n//w
print(x+y-1 if x=1 or y=1 else x+y-2)

n=int(input())
r=n**(1/2)
w=0
for i in range(1,int(r)+1):
  if n%i==0:
    w=i
x,y=w,n//w
if x!=1 and y!=1:
  print(x+y-2)
else:
  print(max(x,y)-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())
fac=1
if n%2==0:
  fac=2
if n%3==0:
  fac=3
for i in range(1,166667):
  if n%(i*6-1)==0:
    fac=i*6-1
  if n%(i*6+1)==0:
    fac=i*6+1
fac+=n//fac-2


n=int(input())

fac=1
s=int(n**(1/2)+1)
for i in range(s):
    if n%(s-i)==0:
        fac=s-i
        break

ans=fac+(n//fac)-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):
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())
datas=prime_factorize(N)
a=1
b=1
for i in range(len(data)):
  if a<b:
    a+=data[i]
  else:
    b+=data[i]

print(max(1,a-1)+max(1,b-1))



import itertools
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())
data=prime_factorize(N)
a=1
b=1
import math
sq=math.sqrt(N)
for i in range(len(data)):
  if a<sq:
    a*=data[i]
  else:
    b*=data[i]

print(a+b-2)


N=int(input())
import math
SQ=int(math.sqrt(N))
minval=10**12
a=1
b=1
for i in range(1,SQ+1):
  if N%i==0:
    newa=i
    newb=N//i
    if abs(newa-newb) < minval:
      minval=abs(newa-newb)
      a=newa
      b=newb

print(a+b-2)

Verdicts: Runtime Error

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**12
square = math.ceil(math.sqrt(N))
print(square)
for i in range(1, square+1):
    if N%i == 0:
        ans = min(ans, int(N/i))
b = int(N/ans)
print(ans + b-2)

import math


N = int(input())

ans = 10**12
square = math.ceil(math.sqrt(N))
for i in range(1, square+1):
    if N%i == 0:
        ans = min(ans, N/i)
b = N/ans
print(int(ans + 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 numpy as np
import itertools
def p(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())
p=p(n)
if len(p)==1:
    print(p[0]-1)
    exit()
a=10**12
b=1
for i in p:
    b*=i
pp=int(len(p)**0.5) 
for k in range(pp,min(,len(p)pp+5)):    
    for i in itertools.combinations(p, k):
        c=np.prod(i)
        a=min(a,c+b//c)
print(a-2)

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

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())
a = 1
while a * a <= N:
  if N % a = 0:
    k = a
  a += 1
print(k + (N // k) - 2)


N = int(input())
a = 1
while a * a <= N:
  if N % a = 0:
    k = a
  a += 1
print(k + (N/k) - 2)


N = int(input())
a = 2
while a * a <= N:
  if N % a = 0:
    k = a
  a += 1
print(k + N//k -2)


N = int(input())
a = 1
while a * a <= N:
  if N % a = 0:
    k = a
  a += 1
print(k + (N//k) -2)


N = int(input())
a = 1
while a * a <= N:
  if N % a = 0:
    k = a
  a += 1
b = N //k
print(b + k - 2)


N = int(input())
a = 1
while a * a <= N:
  if N % a == 0:
    k = a
  a += 1
b = N //k
print(b + k - 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())
s = N-1
for i in range(1, int(N**0.5) + 1):
    for j in range(1, int(N**0.5) + 1):
        if N == i * j:
            flag = i + j - 2

            if flag <= s:
                s = flag

print(s)


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

print(s)

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):
from math in sqrt
n = int(input())

m = int(sqrt(n))

print(m*2-1) 

import sys
n=int(input())
for i in range(int(n**0.5)+1,0,-1):
  if n%i==0:
    print(i + n//i -2)
    sys.exit()
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())
a=()
ans=1e12
l=int(n**0.5)+2
for i in range(1,l):
  if i in a:
    continue
  elif n%i==0:
    a.append(i)
    a.append(n//i)
    ans=min(ans,(i+n//i-2))
print(ans) 

n=int(input())
a=[]
ans=1e12
l=int(n**0.5)+2
for i in range(1,l):
  if n%i==0 and i not in a:
    a.append(i)
    a.append(n//i)
    ans=min(ans,(i+n//i-2))
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):
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
a=int(input())
divisors=make_divisors(a)
divisors.sort()
b=len(divisors)
if b%2==0:
  c = (divisors[int(b/2-0.5)]-1)+(divisors[int(b/2+0.5)]-1)
else:
  c = 2*(divisors[int(b/2)]-1)

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
a=int(input())
divisors=make_divisors(a)
divisors.sort()
b=len(divisors)
if b%2==0:
  c = (divisors[int(b/2-0.5)]-1)+(divisors[int(b/2+0.5)]-1)
else:
  c = 2*(divisors[int(b/2)]-1)
print(c)

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

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

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

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):
def p(n):
    r = []
    a, b = 0, 2
    while b * b <= n:
        if n % b == 0:
            n //= b
            r += [b]
        else:
            b += 1 + a
            a = 1
    if n > 1 : r += [n]
    return r
b = int(input())
m = p(b)
if len(m) == 1:
    print(m[0]-1)
else:
    a = 1
    for i in m:
        if a > b : break
        b //= i
        a *= i
    print(a+b-2)


import random
def p(n):
    r = []
    a, b = 0, 2
    while b * b <= n:
        if n % b == 0:
            n //= b
            r += [b]
        else:
            b += 1 + a
            a = 1
    if n > 1 : r += [n]
    return r
n = int(input())
m = p(n)
ans = n-1
for i in range(2048):
    random.shuffle(m)
    a = 1
    b = n
    for i in m:
        if a >= b : break
        b //= i
        a *= i
    ans = min(ans, a+b-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
def ii():
  return int(input())

N = ii()

def facts(n):
  facts = []
  for i in range(1, int(math.sqrt(n))+1):
    if n%i==0:
      facts.append(i)
  return facts

fs = facts(N)
print(fs)
a = fs[-1]
b = N//a

print(a+b-2)


import math
def ii():
  return int(input())

N = ii()

def facts(n):
  facts = []
  for i in range(1, n):
    if i*i>n:
      break
    if n%i==0:
      facts.append(i)
  return facts

fs = facts(N)
a = fs[-1]
b = N//a

print(a+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 array
import sys
from collections import deque
import math

def input():
    return sys.stdin.readline().rstrip('\n')

N = int(input())


for i in reversed(range(1,int(math.sqrt(N))+1)):
    if N % i == 0:
        j = N // i
        print(i,j,i+j-2)
        sys.exit()


import array
import sys
from collections import deque
import math

def input():
    return sys.stdin.readline().rstrip('\n')

N = int(input())


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

n = int(input())

low = sys.maxsize
a, b = 0, 0
for i in range(math.floor(math.sqrt(n))):
    if n%i == 0 and (i + n//i) <= low:
        a, b = i, n//i
        low = a + b
print(a+b-2)

n = int(input())

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

Verdicts: Runtime Error

Accepted