diff --git a/buggy.py b/buggy.py
--- a/buggy.py
+++ b/buggy.py
@@ -7,7 +7,7 @@
     n = int(math.sqrt(M * 10))
     ans = []
 
-    for a in range(1, n + 1):
+    for a in range(1, min(n, N) + 1):
         b = ceil(M, a)
 
         if b <= N:
