z={} for d in range(1,500): for a in range(1,250000/d-d+1): x=4*d*d+4*a*d z[x]=z.get(x,0)+1 print len([x for x in z if z[x]<=10])