def makep(x): P = [2] p = [2] n = 3 while x > n: for i in p: if n % i == 0: break else: P.append(n) n += 2 while n > p[-1] ** 2: p.append(P[len(p)]) return P maxx = 50000000 prime = makep(int(maxx ** 0.5)) def make(x, y, z): return x ** 2 + y ** 3 + z ** 4 out = set([]) for i in prime: for j in prime: for k in prime: tmp = make(i, j, k) if tmp > maxx: break out.add(tmp) if make(i, j, 2) > maxx: break if make(i, 2, 2) > maxx: break print len(out)