Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def prime(n):
- if n == 2 or n == 3: return True
- if n < 2 or n % 2 == 0: return False
- if n < 9: return True
- if n % 3 == 0: return False
- r = int(n**0.5)
- f = 5
- while f <= r:
- if n % f == 0: return False
- if n % (f+2) == 0: return False
- f += 6
- return True
- total, chain, bestchain, index, primes, bestprime = 0, 0, 0, 0, [], 0
- for x in range(10**6):
- print(x)
- if prime(x):
- primes.append(x)
- if (total + x) >= 10**6:
- if (total + x) >= 10 ** 6:
- total -= primes[index]
- index += 1
- chain -= 1
- continue
- total += x
- chain += 1
- if prime(total) and (total < 10**6):
- if chain > bestchain:
- bestchain = chain
- bestprime = total
- print(bestprime)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement