There is no need to go up to the number to know its factor, going up to the sqrt is enough:
def D(x):
return sum(i**2 + int(((x / i)**2 ** 2 if i * i != x else 0)) for i in range(1, math.floor(x ** 0.5) + 1) if not x%i)
That should speed up quite a bit the computation if you are dealing with big numbers