Find the smallest triangular number with more than 500 factors
Instead of
        if len(a) &gt; 498:
            return True
        else :
            a.clear()
            return False

you could just
        return len(a) &gt; 498

as there's no point in clearing a.
The n-th triangle number is \$\frac{n(n+1)}{2}\$, so you could factor both n and n+1 and combine their factorizations.
Takes less than a second:
from collections import Counter
from math import prod
from functools import cache

@cache
def factorize(n):
    factorization = Counter()
    d = 2
    while d * d &lt;= n:
        while n % d == 0:
            factorization[d] += 1
            n //= d
        d += 1
    if n &gt; 1:
        factorization[n] += 1
    return factorization

n = triangle = 0
while True:
    n += 1
    triangle += n
    factorization = factorize(n) + factorize(n + 1) - factorize(2)
    divisors = prod(power + 1 for power in factorization.values())
    if divisors &gt; 500:
        print(triangle, divisors)
        break