def pe010d(l=2000000): t = time() p = sievePrime(l) s = 0 for i in range(1, l): if p[i] == 1: s += i return s, time() - t
def pe007(l=10001, m=20): t = time() p = sievePrime(l * m) i = 0 while l > 0: if p[i] == 1: l -= 1 i += 1 return i - 1, time() - t
def pe087(l=50000000): t = time() s = set() p = sievePrime(int(l ** 1 / 2)) p2 = [x ** 2 for x in range(int(l ** 1 / 2)) if p[x] == 1] p3 = [x ** 3 for x in range(int(l ** 1 / 3)) if p[x] == 1] p4 = [x ** 4 for x in range(int(l ** 1 / 4)) if p[x] == 1] for a in p2: for b in p3: s1 = a + b if s1 >= l: break for c in p4: s2 = s1 + c if s2 >= l: break s.add(s2) return len(s), time() - t
def pe035(l=1000000): t = time() p = sievePrime(l) def checknum(l): if p[l] == 0: return False n = str(l) dd = 10 ** (len(n) - 1) for i in n: if p[l] == 0: return False l = ((l % 10) * dd) + (l // 10) return True r = 0 for a in range(l): if checknum(a): r += 1 #print(a) return r, time() - t
def pe037(l=1000000): t = time() p = sievePrime(l) def checknum(l): if p[l] == 0: return False ll = l for _ in str(ll): if p[ll] == 0: return False ll //= 10 ll = l for i in range(len(str(ll)), 0, -1): if p[ll] == 0: return False ll %= (10 ** (i - 1)) return True r = 0 for a in range(11, l): if checknum(a): r += a #print(a) return r, time() - t
def pe041(): t = time() p = sievePrime(7654322) # 98xxxxxxx all pandigitals mod3==0 s = set('7654321') for i in range(7654321, 1234567, -1): if p[i] == 1 and s == set(str(i)): return i, time() - t