qyliang/CodeNanoFix huggingface dataset:
Buggy code:
def dis(xa,ya):
  return abs(xa - 1) + abs(ya - 1)

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

Fixed code:
def dis(xa,ya):
    return abs(xa - 1) + abs(ya - 1)

n = int(input())
ans = 2*n
i = 1
while i*i <= n:
    if (n % i == 0):
        ans = min(ans, dis(i,n//i))
    i += 1
print(ans)
Buggy code:
def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    table.sort()
    return table

N = int(input())

n = []
n = divisor(N)
print(n)

cnt = 999999999999999
if len(n) >= 2:
    for i in range(0,len(n)//2,1):
        t = int(n[i])-1 + int(n[len(n)-i-1])-1
        if cnt > t:
            cnt = t
print(cnt)



Fixed code:
def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    #table = list(set(table))
    table = list(table)
    table.sort()
    return table

N = int(input())

#for N in range(1000000000000):
n = []
n = divisor(N)
#print(n)

cnt = 999999999999999
for i in range(0,len(n)//2,1):
    t = int(n[i])-1 + int(n[len(n)-i-1])-1
    if cnt > t:
        cnt = t
print(cnt)
Buggy code:
N = int(input())
import math

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

    divisors.sort()
    return divisors

a = make_divisors(N)
if len(a)%2 == 1:
  print(2*int(math.sqrt(N))-2)
else:
  b = a[len(a)/2-1]
  c = a[len(a)/2]
  print(b+c-2)

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

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

    divisors.sort()
    return divisors

a = make_divisors(N)
if len(a)%2 == 1:
  print(2*int(math.sqrt(N))-2)
if len(a)%2 == 0:
  b = a[int(len(a)/2)-1]
  c = a[int(len(a)/2)]
  print(b+c-2)
Buggy code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

N = k()
ans = 1000000

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

print(ans)


Fixed code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

N = k()
ans = N-1

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

print(ans)
Buggy code:
n = int(input())
ans = 10**12

for k in range(1,n+1//2):
    if n%k == 0 :
        m = n//k + k - 2
        if ans > m:
            ans = m

print(m)

Fixed code:
n = int(input())
ans = 10**12

for k in range(1,int((n)**0.5)+2):
    if n%k == 0 :
        m = n//k + k - 2
        if ans > m:
            ans = m
print(ans)
Buggy code:
import math

N = int(input())

a = math.floor(math.sqrt(N))

while N % a != 0:
    a -= 1

b =N/a
print(a + b -2)

Fixed code:
import math

N = int(input())

a = int(math.sqrt(N))

while N % a != 0:
    a -= 1

b = N // a
print(a + b -2)
Buggy code:
N = int(input())
x = N
y = N
ansx = N
ansy = N
ans = []
n = int(N**0.5)
for i in range(n+1):
    if N%(i+1) == 0:
        ans.append(i+1)
ans.append(N)
if(ans[1]==N):
    print(N-1)
else:
    for i in range(len(ans)):
        if ansx > ans[i]:
            if ansy > N//ans[i]:
                ansx = ans[i]
                ansy =int(N//ans[i])
    print(ansx + ansy -2)

Fixed code:
N = int(input())
x = N
y = N
ansx = N
ansy = N
ans = []
n = int(N**0.5)
if N**0.5 == int(N**0.5):
    print(int(N**0.5)*2-2)
else:
    for i in range(n+1):
        if N%(i+1) == 0:
            ans.append(i+1)
    ans.append(N)
    if(ans[1]==N):
        print(N-1)
    else:
        for i in range(len(ans)):
            if ansx+ansy>ans[i] + int(N//ans[i]):
                ansx = ans[i]
                ansy =int(N//ans[i])
        print(ansx + ansy -2)
Buggy code:
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)

Fixed code:
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)
Buggy code:
ef div_make(n):
    divisor =[]
    n=int(n)
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            divisor.append([i,n//i])
    return divisor

a=int(input())

lst=[]
for i in div_make(a):
    lst.append(i[0]+i[1])
ans=0
ans=min(lst)-2
print(ans)

Fixed code:
def div_make(n):
    divisor =[]
    n=int(n)
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            divisor.append([i,n//i])
    return divisor

a=int(input())

lst=[]
for i in div_make(a):
    lst.append(i[0]+i[1])
ans=0
ans=min(lst)-2
print(ans)
Buggy code:
=int(input())
r=n-1
for i in range(2,int(n**0.5)):
    if (n%i==0):
        s=n//i+i-2
        if s<r:
            r=s
print(r)


Fixed code:
n=int(input())
r=n-1
for i in range(1,int(n**0.5)+1):
    if (n%i==0):
        s=(n//i)+i-2
        if s<r:
            r=s
print(r)
Buggy code:
n=int(input())
end=n**(1/2)
for i in range(end,1,-1):
  if n%i==0:
    j=n//i
    print(i*j-2)
    break

Fixed code:
n=int(input())
end=int(n**(1/2))
for i in range(end,0,-1):
  if n%i==0:
    j=n//i
    print(i+j-2)
    break
Buggy code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

N = int(input())
list =make_divisors(N)
list_rev=sorted(list, reverse=True)

ans = 10**9
for i in range(len(list)//2 + 1):
  tmp = (list[i]-1)+(list_rev[i]-1)
  if tmp < ans:
    ans=tmp

print(ans)


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

    divisors.sort()
    return divisors

N = int(input())
list =make_divisors(N)
list_rev=sorted(list, reverse=True)

ans = 10**15
for i in range(len(list)//2 + 1):
  tmp = (list[i]-1)+(list_rev[i]-1)
  if tmp < ans:
    ans=tmp

print(ans)
Buggy code:
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))

Fixed code:
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))
Buggy code:
n=int(input())
temp=10**13
for i in range(1,n+1):
    if n%i==0:temp=min(temp,i+n/i)
print(temp-2)

Fixed code:
n=int(input())
temp=10**13
for i in range(1,int(n**(1/2))+1):
    if n%i==0:temp=min(temp,i+n/i)
print(int(temp-2))
Buggy code:
n = int(input())
ans = 1e14
for i in range(1, int(n**(1/2) + 1)):
    if n % i == 0:
        ans = min(ans, i + n / i - 2)

print(ans)


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

print(ans)
Buggy code:
N = int(input())

mul = []
for i in range (1,round(N**(1/2) + 1)):
    if N%i == 0:
        mul.append(i)
        mul.append(N//i)
print(mul)

min = mul[0] + mul[1]
for i in range (0,len(mul),2):
    print(i)
    if mul[i] + mul[i+1] <= min:
        min = mul[i] + mul[i+1]

print(min-2)

Fixed code:
N = int(input())

mul = []
for i in range (1,round(N**(1/2) + 1)):
    if N%i == 0:
        mul.append(i)
        mul.append(N//i)
#print(mul)

min = mul[0] + mul[1]
for i in range (0,len(mul),2):
    if mul[i] + mul[i+1] <= min:
        min = mul[i] + mul[i+1]

print(min-2)
Buggy code:
n = int(input())
for i in range (2, n):
    if n % i == 0:
        j = n // i
        anser = i + j - 2
    if i * i > n:
        break
print(anser)

Fixed code:
n = int(input())
anser = n - 1
for i in range (2, n):
    if n % i == 0:
        j = n // i
        anser = i + j - 2
    if i * i > n:
        break
print(anser)
Buggy code:
num_s = input()
num = int(num_s)

def check(num):
    n = []
    for i in range(1, int(num**0.5)+1):
        if i > num:
            break
        if (num % i == 0):
            n.append(i)
    return n


ans = check(num)
a = max(ans)
b = num / a

if a == 1:
    a = 1
else:
    a = a - 1
if b == 1:
    b = 1
else:
    b = b - 1

print(int(a + b))

Fixed code:
num_s = input()
num = int(num_s)

def check(num):
    n = []
    for i in range(1, int(num**0.5)+1):
        if i > num:
            break
        if (num % i == 0):
            n.append(i)
    return n
ans = check(num)
a = max(ans)
b = int(num / a)


a = a - 1
b = b - 1

print(a + b)
Buggy code:
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))

Fixed code:
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))
Buggy code:
import math
n= int(input())
x=n+1
for i in range(2,int(math.sqrt(n)+1)):
  if n%i==0:
    x= i+ (n%i)
print(x-2)

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

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


Fixed code:
import math
n=int(input())

to=int(math.sqrt(n))
a=n*2
for i in range(1,to+1):
    if n%i==0:
        a=min(a,n//i+i)

print(a-2)
Buggy code:
import math
n = int(input())
a = 0
b = 0
ans = 0
for i in range(int(math.sqrt(n)),1,-1):
  print(i)
  a = i
  b = n/i
  if b%1 == 0 and b<10:
    ans = a+b-2
    break
print(a,b,ans)

Fixed code:
import math
n = int(input())
a = 0
b = 0
ans = 0
for i in range(int(math.sqrt(n)),0,-1):
  a = i
  b = n/i
  if b%1 == 0:
    ans = int(a+b-2)
    break
print(ans)
Buggy code:
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)))


Fixed code:
import math
n = int(input())

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

print(int(min(a)))
Buggy code:
N=int(input())
ans=float('inf')
i=2
while i*i<=N:
  if N%i==0:
    ans = min(ans,i+(N//i)-2)
  i+=1
print(ans)

Fixed code:
N=int(input())
ans=float('inf')
i=2
while i*i<=N:
  if N%i==0:
    ans = min(ans,i+(N//i)-2)
  i+=1
if ans==float('inf'):
  ans = N-1
print(ans)
Buggy code:
N=int(input())
list=[]
for t in range(1,N+1):
  if N%t==0:
    list+=[(t,int(N/t))]
mini=N+1
for (p,q) in list:
  if p+q<mini:
    mini=p+q
print(mini-2)

Fixed code:
N=int(input())
list=[]
for t in range(1,int(N**(1/2)+2)):
  if N%t==0:
    list+=[(t,int(N/t))]
mini=N+1
for (p,q) in list:
  if p+q<mini:
    mini=p+q
print(mini-2)
Buggy code:
n=int(input())
c=10**9
for i in range(1,n**0.5):
    if n%i==0:
        j=n/i
        if i+j < c:
            c=int(i+j)

print(c-2)

Fixed code:
n=int(input())
c=10**13
for i in range(1,int(n**0.5)+1):
    if n%i==0:
        j=int(n/i)
        if i+j < c:
            c=int(i+j)

print(c-2)
Buggy code:
import math

N = int(input())
sum = N - 1
b = int(math.sqrt(N))
for i in range(2, b+1):
    if(N%i==0):
        if((a/i+i-2)<=sum):
            sum = N/i+i-2

print(sum)

Fixed code:
import math

N = int(input())
sum = N - 1
b = int(math.sqrt(N))
for i in range(2, b+1):
    if(N%i==0):
        if((N//i+i-2)<=sum):
            sum = N//i+i-2

print(sum)
Buggy code:
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)

Fixed code:
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))
Buggy code:
import math

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

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

Fixed code:
import math

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

for i in range(m):
  if n % (m - i) == 0:
    print(int(m-i + n/(m-i) - 2))
    break
Buggy code:
n = int(input())
ans = 10 ** 12 +1
for i in range(n):
  k = i+1
  if n%k == 0:
    ans = min(ans, n//k + k -2)
  if i ** 2 < n:
    break
print(ans)

Fixed code:
n = int(input())
ans = 10 ** 12 +1
for i in range(n):
  k = i+1
  if n%k == 0:
    ans = min(ans, n//k + k -2)
  if i ** 2 > n:
    break
print(ans)
Buggy code:
import math

n=int(input())

min=-1
for i in range(1,int(math.sqrt(n))+1):
    if n%i==0:
        j=int(n/i)
        print("divide",i,j)
        calc=j+i-2
        if min==-1 or min>calc:
            min=calc

print(min)


Fixed code:
import math

n=int(input())

min=-1
for i in range(1,int(math.sqrt(n))+1):
    if n%i==0:
        j=int(n/i)
        calc=j+i-2
        if min==-1 or min>calc:
            min=calc

print(min)
Buggy code:
import math
x=int(input())
s=set()
y=int(math.sqrt(x))
for i in range(y,0,-1):
  print(i)
  if x%i == 0:
    a=i+x//i-2
    s.add(a)
    if min(s)-a <0:
      break
print(min(s))

Fixed code:
import math
x=int(input())
s=set()
y=int(math.sqrt(x))
for i in range(y,0,-1):
  if x%i == 0:
    a=i+x//i-2
    s.add(a)
    if min(s)-a <0:
      break
print(min(s))
Buggy code:
a=int(input())
s=[]
for i in range(1,int(0.5*a+1)):
  if a%i==0:
    s.append(i+a//i)
print(min(s)-2)

Fixed code:
n = int(input())
s=[]
a=0
for i in range(1, int(n ** 0.5) + 1):
    if n % i == 0:
      a=n//i
      s.append(n//i+n//a)
print(min(s)-2)
Buggy code:
def devide2two(n):
    arr=[]
    arr.append((n-1))
    for i in range(2, int(-(-n**0.5//1))+1):
        if n%i==0:
            a = n/i
            arr.append(i-1+ a-1)
    
    return min(arr)
n = input()
print(devide2two(n))

Fixed code:
def devide2two(n):
    arr=[]
    arr.append((n-1))
    for i in range(2, int(-(-n**0.5//1))+1):
        if n%i==0:
            a = n/i
            arr.append(i-1+ a-1)
    
    return min(arr)
n = int(input())
print(int(devide2two(n)))
Buggy code:
N = int(input())

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

div = make_divisors(N)
if len(div) % 2 == 0:
	ind_2 = len(div) // 2
	ind_1 = ind_2 - 1
	print(div[ind_1] + div[ind_2])
else:
	ind = len(div) // 2
	print(div[ind] * 2)

Fixed code:
N = int(input())

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

div = make_divisors(N)
if len(div) % 2 == 0:
	ind_2 = len(div) // 2
	ind_1 = ind_2 - 1
	print(div[ind_1] + div[ind_2] -2)
else:
	ind = len(div) // 2
	print(div[ind] * 2 -2)
Buggy code:
N = int(input())
m = N
for a in range(2, int(N**(0.5)+2)):
    if N%a == 0:
        m = min(m, a + N//a - 2)
print(m)

Fixed code:
N = int(input())
m = N
for a in range(1, int(N**(0.5)+2)):
    if N%a == 0:
        m = min(m, a + N//a - 2)
print(m)
Buggy code:
n = int(input())
s = int(math.sqrt(n))
a = 0
for i in range(s, 0, -1):
    if n % i == 0:
        a = i
        break
if a == 0:
    print(n - 1)
else:
    print(int((a - 1) + (n / a - 1)))

Fixed code:
import math
n = int(input())
s = int(math.sqrt(n))
a = 0
for i in range(s, 0, -1):
    if n % i == 0:
        a = i
        break
if a == 0:
    print(n - 1)
else:
    print(int((a - 1) + (n / a - 1)))
Buggy code:
# -*- coding: utf-8 -*-
n = int(input())

ans = pow(10, 30)
for i in range(1, int(pow(n, 0.5)) + 1):
    for j in range(i, n):
        #print(i, j)
        if i * j == n and i + j - 2 < ans:
            ans = i + j - 2
print(ans)


Fixed code:
# -*- coding: utf-8 -*-
n = int(input())

ans = pow(10, 30)
for i in range(1, int(pow(n, 0.5)) + 1):
    if n / i == n // i:
        j = n // i
        if i + j - 2 < ans:
            ans = i + j - 2
print(ans)
Buggy code:
# -*- coding: utf-8 -*-
n = int(input())

tmp = 10 ** 6
tmp2 = 1
tmp3 = 1
for i in range(1, 10 ** 6):
    if n % i == 0 and i + (n / i) < tmp:
        tmp = i + (n // i)
        tmp2 = i
        tmp3 = n // i
print(tmp2 + tmp3 - 2)


Fixed code:
# -*- coding: utf-8 -*-
n = int(input())

tmp = 10 ** 24
tmp2 = 1
tmp3 = 1
for i in range(1, 10 ** 6 + 1):
    if n % i == 0 and i + (n / i) < tmp:
        tmp = i + (n // i)
        tmp2 = i
        tmp3 = n // i
print(tmp2 + tmp3 - 2)
Buggy code:
import math
n = int(input())
sq_n = int(math.sqrt(n))
s_lis = []
e_lis = []
for i in range(1, sq_n + 1):
    if n % i == 0:
        s_lis.append(i)
        e_lis.append(n // i)
min_len = n + 1 - 2
for s, e in zip(s_lis, e_lis):
    print(s, e)
    min_len = min(min_len, s + e - 2)
print(min_len)

Fixed code:
import math
n = int(input())
sq_n = int(math.sqrt(n))
s_lis = []
e_lis = []
for i in range(1, sq_n + 1):
    if n % i == 0:
        s_lis.append(i)
        e_lis.append(n // i)
min_len = n + 1 - 2
for s, e in zip(s_lis, e_lis):
    min_len = min(min_len, s + e - 2)
print(min_len)
Buggy code:
from math import sqrt

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

Fixed code:
from math import sqrt

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

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

    # divisors.sort()
    return divisors

l = make_divisors(n)
ans = n
for i in range(len(l)):
  for j in range(len(l)):
    if n == l[i] * l[j]:
      ans = min(ans,l[i]+l[j])
print(ans - 2)

Fixed code:
n = int(input())

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

    # divisors.sort()
    return divisors

l = make_divisors(n)
ans = n
for i in range(len(l)):
  ans = min(ans,(l[i] + n // l[i]) - 2)
print(ans)
Buggy code:
import math
n = int(input())
root = int(math.sqrt(n))
ans = 0
flag = 0
for i in range(1, root+1):
    if n % i == 0:
        flag = 1
        ans = int((n/i)) + i - 2
        break
print(ans)

Fixed code:
import math
n = int(input())
flag = True
ans = n - 1
for i in reversed(range(2, int(math.sqrt(n))+1)):
  if (n%i == 0):
    ans = i + n//i - 2
    break
print(ans)
Buggy code:
N = int(input())
import math
A = []
for i in range(1,int(math.sqrt(N))+1):
    if N % i == 0:
        A.append(i+N/i-2)
print(min(A))

Fixed code:
N = int(input())
import math
A = []
for i in range(1,int(math.sqrt(N))+1):
    if N % i == 0:
        A.append(i+N/i-2)
print(int(min(A)))
Buggy code:
n = int(input())
min_ = n -1 
for i in range(1, n**0.5+10):
  if n % i != 0:
    continue
  else:
    min_ = min(min_, i-1+n//i-1)
    
print(min_)

Fixed code:
n = int(input())
min_ = n -1 
for i in range(1, int(n**0.5)+10):
    if n % i != 0:
        continue
    else:
        min_ = min(min_, i-1+(n//i)-1)
    
print(min_)
Buggy code:
a=int(input())
c=a+1
for i in range(10000000000,2,-1):
	if a%i==0:
       b=a/i
       if i+b<c:
       	c=i+b
print(int(c-2))

Fixed code:
a=int(input())
c=a+1
for i in range(1,10000000,1):
    if a%i==0:
        b=a/i
        if i+b<=c:
            c=i+b
print(int(c-2))
Buggy code:
import sys

def divisor(n):
    i = 1
    l = []
    while i * i <= n:
        if n%i == 0:
            l.append(i)
            l.append(n//i)
        i += 1
    l = list(set(l))
    l.sort()
    return l

stdin = sys.stdin

ni = lambda: int(ns())
ns = lambda: stdin.readline()

N = ni()
ans = 0
if N > 1:
    div = divisor(N)
    print(div, div[len(div)//2 - 1])
    if len(div) > 1:
        i = div[len(div)//2 - 1] - 1
        j = (N // (div[(len(div)//2) - 1]))  - 1
        ans = i + j
    else:
        ans = 1
elif N == 1:
    ans = 0
else:
    ans = 1

print(ans)

Fixed code:
import sys

def divisor(n):
    i = 1
    l = []
    while i * i <= n:
        if n%i == 0:
            l.append(i)
            l.append(n//i)
        i += 1
    l.sort()
    return l

stdin = sys.stdin

ni = lambda: int(ns())
ns = lambda: stdin.readline()

N = ni()
ans = 0
if N > 1:
    div = divisor(N)
    #print(div, div[len(div)//2 - 1])
    if len(div) > 1:
        i = div[len(div)//2 - 1] - 1
        j = (N // (div[(len(div)//2) - 1]))  - 1
        ans = i + j
    else:
        ans = 1
elif N == 1:
    ans = 0
else:
    ans = 1

print(ans)
Buggy code:
N = int(input())
s = N
i = 1
while i**2 <= N:
    if N % i == 0:
        s = i
    i += 1

ans = N/s + s - 2
print(ans)

Fixed code:
N = int(input())
s = N
i = 1
while i**2 <= N:
    if N % i == 0:
        s = i
    i += 1

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

Fixed code:
N = int(input())
root = int(N**0.5)
print(min([i + N // i -2 for i in range(1, root+1) if N % i == 0]))
Buggy code:
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


Fixed code:
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
Buggy code:
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

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

    #divisors.sort()
    return divisors

n = int(input())

if is_prime(n) == True:
    print(n-1)
else:
    ls = (make_divisors(n))
    print(ls)
    if (n / ls[-1]) == ls[-1]:
        print(ls[-1]+ls[-1]-2)
    else:
        print(ls[-1]+ls[-2]-2)
    

Fixed code:
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

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

    #divisors.sort()
    return divisors

n = int(input())

if is_prime(n) == True:
    print(n-1)
else:
    ls = (make_divisors(n))
    if (n / ls[-1]) == ls[-1]:
        print(ls[-1]+ls[-1]-2)
    else:
        print(ls[-1]+ls[-2]-2)