Yeah I changed it to make it better. Now
newX = E%2
if(newX == 1):
dShift = 6
else:
dShift = 4
newD = int((newX*(newX+2)+E)//2)
newA = newD - newX
while(gcd(newD-D,newA) == 1):
newX += 2
newD += dShift
dShift += 4
newA = newD - newX
newA = D - newX