Skip to content

Instantly share code, notes, and snippets.

@Radcliffe
Last active February 3, 2018 03:26
Show Gist options
  • Save Radcliffe/15ab5a918220cc9b0641bc2e34bdc646 to your computer and use it in GitHub Desktop.
Save Radcliffe/15ab5a918220cc9b0641bc2e34bdc646 to your computer and use it in GitHub Desktop.
A268035: a(n) is the smallest integer m such that each of the numbers m, 2*m, 3*m, ..., n*m is the sum of two successive primes.
"""
Author: David Radcliffe (2018-02-02)
I am interested in numbers that are sums of two successive primes:
5, 8, 12, 18, 24, 30, 36, 42, 52, 60, 68, 78, 84, 90, 100, ...
Note that 2+3=5, 3+5=8, 5+7=12, 7+11=18, and so on.
This is sequence A001043 in the On-Line Encyclopedia of Integer Sequences.
Somebody (I forget who) observed that if N is the sum of two successive primes,
then 2N is likely to be the sum of two successive primes as well. For example:
5 + 7 = 12 and 11 + 13 = 24
13 + 17 = 30 and 29 + 31 = 60
19 + 23 = 42 and 41 + 43 = 84
This led me to wonder if there exist arbitrarily long sequences
N, 2N, 3N, ..., kN
where each term is the sum of successive primes. So I proposed a new
sequence which is defined as follows:
a(k) = N if N is the smallest positive integer so that
every number in the set {N, 2N, 3N, ..., kN} is the sum
of two successive primes.
This is sequence A268035 in the On-Line Encyclopedia of Integer Sequences.
(See https://oeis.org/A268035)
"""
# https://github.com/hickford/primesieve-python
import primesieve
from time import time
def a001043():
"""Generates numbers that are the sum of two consecutive primes."""
it = primesieve.Iterator()
prime = it.next_prime()
while True:
next_prime = it.next_prime()
yield prime + next_prime
prime = next_prime
def multi(k):
"""Generates numbers N so that each of the first k multiples of N
is the sum of two consecutive primes."""
seq = a001043()
if k == 1:
for s in seq: # This is an infinite loop! Use with caution.
yield (s, s)
current = next(seq)
for first, last in multi(k-1): # This is also an infinite loop.
last += first
while current < last:
current = next(seq)
if current == last:
yield (first, last)
def a268035(N):
"""Calculate and display the first N terms of Sequence A268035."""
for n in range(1, N + 1):
start_time = time()
# We use the next() function to return the first result from an infinite iterator.
print(n, next(multi(n))[0], time() - start_time)
a268035(10)
@Radcliffe
Copy link
Author

N.B. It is not difficult to prove that there does not exist an infinite sequence {N, 2N, 3N, 4N, ...} such that every term is the sum of two successive primes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment