from math import sqrt, ceil


def divisor_generator(n):
    yield 1
    for i in range(2, ceil(sqrt(n))):
        if n % i == 0:
            yield i
            yield n // i


def is_perfect(n):
    return n == sum(divisor_generator(n))

def divisor_generator(n):
    big_factors = {1}
    for i in range(2, n):
        if i in big_factors:
            break
        if n % i == 0:
            big_factors.add(n // i)
            yield i
    yield from big_factors


def is_perfect(n):
    return n == sum(divisor_generator(n))

--- 
+++ 
@@ -1,12 +1,12 @@
+from math import sqrt, ceil
+
+
 def divisor_generator(n):
-    big_factors = {1}
-    for i in range(2, n):
-        if i in big_factors:
-            break
+    yield 1
+    for i in range(2, ceil(sqrt(n))):
         if n % i == 0:
-            big_factors.add(n // i)
             yield i
-    yield from big_factors
+            yield n // i
 
 
 def is_perfect(n):
Refactor to give faster solution
