target=50000000 s={} for a in range(2,target): d=a/4+1 n=a*(4*d-a) while d < a and n < target: s[n]=s.get(n,0)+1 d+=1 n=a*(4*d-a) print sum(s[i]==1 for i in s)