1

Question:

Given a number, I need to find out which of the following rows/lists it exists in. But I don't want generate them, given that there are a lot of lists and they grow bigger over time.

We are given the following patterns.

  1. $a = \textbf{0}, 4, 5, 9, 10, 14, 15, 19, 20, ..., n \quad\textbf{[+4, +1]}$

  2. $b = \textbf{1}, 5, 8, 12, 15, 19, 22, 26, 29, ..., n\quad\textbf{[+4, +3]}$

  3. $c = \textbf{1}, 9, 12, 20, 23, 31, 34, 42, 45, ..., n\quad\textbf{[+8, +3]}$

  4. $d = \textbf{2}, 10, 15, 23, 28, 36, 41, 49, 54, ..., n\quad\textbf{[+8, +5]}$

  5. $e = \textbf{2}, 14, 19, 31, 36, 48, 53, 65, 70, ..., n\quad\textbf{[+12, +5]}$

  6. $f = \textbf{3}, 15, 22, 34, 41, 53, 60, 72, 79, ..., n\quad\textbf{[+12, +7]}$

  7. $g = \textbf{3}, 19, 26, 42, 49, 65, 72, 88, 95, ..., n\quad\textbf{[+16, +7]}$

  8. $h = \textbf{4}, 20, 29, 45, 54, 70, 79, 95, 104, ..., n\quad\textbf{[+16, +9]}$

  9. $i =$ Etc.

Examples:

Where is 4? -> 4 is in list 1 (1,2)

Where is 5? -> 5 is in list 1 (1,3) and/or list 2 (2,2) [one answer is enough]

Only the list is of importance, the position within not so much.

When it comes to finding a given number, the amount of testing is also of crucial importance. As the whole point of this is to try and achieve the most optimal time complexity.


Hades
  • 61
  • Is the number of patterns limited to those (a-h) or does it continue? – Andrei Dec 19 '18 at 00:32
  • @Andrei it continues (i'll edit the question) – Hades Dec 19 '18 at 00:33
  • Then the trivial solution is that every number appears twice as the first element in two consecutive series. 1 appears in series 1 and 2, 2 in 3 and 4, 4 in 7 and 8, and so on – Andrei Dec 19 '18 at 00:35
  • @Andrei, hmm I'm not looking for those, these are just the starting point for each series. (i'll edit the question) – Hades Dec 19 '18 at 00:41
  • 1
    Why did you number the rows 1(a), 2(b), etc. as opposed to just 1, 2, 3, ... or a, b, c ...? Is there a significance? Secondly, the starting element and subsequent element of each row is parameterized - for example, row 3(c) only has two kinds of numbers: $11n+1$ and $11n+9$ for $n=0,1,2,...$. So for any number $k$, you should be able to check the divisibility of $(k-1)$ and $(k-9)$ by 11, and determine membership in 3(c). I think you might be able to come up with a pre-determined set of rules with this approach. – Godfather Dec 19 '18 at 00:43
  • 1
    Please use Mathjax to format your math, format bold math with \textbf{} in Mathjax (not asterisks). Also please summarise the question in the introductory paragraph; there's so much waffle here, it's quite hard to read through. – Jam Dec 20 '18 at 16:21
  • I gather that the question in the title isn't what is actually sought, but the answer to it may be of interest: the numbers that appear in at least one sequence, but not as the initial number, are precisely those numbers $n$ such that $6n+1$ and $6n+5$ are not both prime. This follows from Barry Cipra's answer. Also see this OEIS sequence. – Will Orrick Dec 20 '18 at 19:17
  • 1
    @Jam thanks for the advice, I've made the changes according to MathJax and did some formatting. – Hades Dec 20 '18 at 19:21
  • @Eli Excellent! The easier and more accessible you make your question, the better answers you'll get from it. – Jam Dec 20 '18 at 19:22
  • @WillOrrick you an the numbers that are not in the lists? – Hades Dec 20 '18 at 19:29
  • @WillOrrick could we devise a function for that sequence? – Hades Dec 20 '18 at 20:02
  • Perhaps it's better to say that $N$ is on one of your lists if one or both of $6N+1$ and $6N+5$ are composite. It seems to me that finding a formula for the OEIS sequence (or for its complement) is likely to be as or more difficult than the problem of finding a practical formula for the $n^\text{th}$ prime--a notorious open problem. – Will Orrick Dec 21 '18 at 07:04
  • @WillOrrick, again the time complexity would be massive as that would just be prime factorization. And what if given other patterns that aren't corrolated with primes? My way might bit out there, but its repeatable or adjustable no matter what patterns and trying for optimal time complexity – Hades Dec 21 '18 at 08:56
  • I hadn't proposed any algorithm; I merely gave a mathematically equivalent formulation of the question. In my understanding, your goal is an efficient algorithm for finding the $n$th natural number $N$ with the property that the pair $(6N+1,6N+5)$ are not cousin primes. This answer discusses the state of the art for finding the $n$th prime. The much more primitive state of the art for finding... – Will Orrick Dec 22 '18 at 14:01
  • ...the $n$th twin-prime pair--finding the $n$th cousin-prime pair will be similar--is described here It is believed, but not proved, that there are infinitely-many cousin-prime pairs. If it turned out there were only finitely many, then, beyond a certain point, your list would contain all natural numbers, and there would be an extremely efficient algorithm for finding the $n$th number. – Will Orrick Dec 22 '18 at 14:01
  • @WillOrrick You shouldn't really think of primes in this matter to be honest, as the patterns I could give could've been totally different, and yet it would've been calculateable. The fact that there is pattern allows us to know a number at a certain position, which I have already proven in my question. And in order to achieve a really good time complexity I just need to find a way to spit out the numbers chronilogicaly. – Hades Dec 22 '18 at 14:46
  • I don't have much more to say, except that inverting a pattern can be much more difficult than generating the pattern. Modern cryptography is based on this idea. Barry Cipra has already said this, but it bears repeating: the pattern $$\begin{matrix} 4 & 6 & 8 & \ldots\ 6 & 9 & 12 & \ldots\ 8 & 12 & 16 & \ldots\\vdots\end{matrix}$$ is easy to generate: row $i$, column $j$ is $(i+1)(j+1)$. But displaying the numbers chronologically, 4, 6, 8, 9, 10, 12, $\ldots$ amounts to generating the composite numbers (non-primes) in order. Your pattern is of the same type, but a bit more complicated. – Will Orrick Dec 22 '18 at 16:57

2 Answers2

5

This is more of an extended comment than an answer, but it might help focus on what needs to be done. (Actually, it's now more of an answer than an extended comment; see the Added later section.)

You are fundamentally asking a question about computational complexity: Given a large number $N$ (let's say $N=10{,}000$), how efficiently can we find the smallest $n$ such that $N$ appears in list $(n)$? It's obvious that $N$ is the first entry in lists $(2N)$ and $(2N+1)$; the live question is whether it appears in any earlier lists.

The entries in list $(2k-1)$ (for $k\ge1$) are the nonnegative integers congruent to $k-1$ and $5k-1$ mod $6k-1$, while the entries in list $(2k)$ are the positive integers congruent to $k$ and $5k$ mod $6k+1$. So if $N$ belongs to an earlier list, we have one (or more) of the following:

$$N=\begin{cases} k-1+(6k-1)m\\ 5k-1+(6k-1)m\\ k+(6k+1)m\\ 5k+(6k+1)m \end{cases}$$

for some $k\ge1$ and $m\ge0$.

You might compare this to the question of factorization: It's obvious that $N$ divides $N$, the question is whether any smaller integer (greater than $1$) divides $N$, i.e. does $N=(k+1)(m+1)$ have any solutions with $k,m\ge1$? (To be somewhat more precise, for factorization we'd be asking for the smallest prime factor.) Factorization is known to be in NP and suspected to be in NP\P. The problem here is similarly in NP; the question is where it stands with respect to P.

Added later: It occurs to me the connection with factorization is indeed quite strong. For example,

$$N=k+(6k+1)m\iff6N=36km+6k+6m=(6k+1)(6m+1)-1$$ and $$N=5k+(6k+1)m\iff6N=36km+30k+6m=(6k+1)(6m+5)-5$$

so testing $N$ for membership in list $(2k)$ boils down to considering possible factorizations of $6N+1$ and $6N+5$. For $N=10{,}000$, for example, $60{,}001=29\cdot2069$, neither of which is congruent to $1$ mod $6$, but $60{,}005=5\cdot11\cdot1091=55\cdot1091$, so $N=10{,}000$ appears in list $(18)$. One can do something similar for membership in list $(2k-1)$:

$$N=k-1+(6k-1)m\iff6N=36km+6k-6m-6=(6k-1)(6m+1)-5$$ and $$N=5k-1+(6k-1)m\iff6N=36km+30k-6m-6=(6k-1)(6m+5)-1$$

If, as appears to be desired, the first element of each list is to be omitted, the condition $m\ge0$ can be replaced with $m\ge1$ and the second and fourth conditions above can be modified by replacing $m$ with $m-1$. The conditions for membership in list $(2k)$ are then

$$N+1=(6k+1)(6m+1)$$ and $$N+5=(6k+1)(6m-1)$$

while the conditions for membership in list $(2k-1)$ are

$$N+5=(6k-1)(6m+1)$$ and $$N+1=(6k-1)(6m-1)$$

all with $k\ge1$ and $m\ge1$. At least one of these four conditions will be satisfied if and only if at least one of $6N+1$ and $6N+5$ is composite, that is, if $(6N+1,6N+5)$ is not a pair of cousin primes.

Will Orrick
  • 18,220
Barry Cipra
  • 79,832
  • @Eli, I got $18$ for $N=10{,}000$ exactly as described: by factoring $60,005$ and massaging the result into a factorization with a nontrivial factor congruent to $1$ mod $6$, namely $55=6\cdot9+1$, which gave $k=9$ so $2k=18$. (The number $60{,}005$ is obviously divisible by $5$, and it's easy to see that $12{,}001$ is divisible by $11$, but I took the lazy way out and had a website do the factoring for me.) – Barry Cipra Dec 19 '18 at 21:51
  • Small correction: the entries in sequence $2k-1$ are the nonnegative integers congruent to $k-1$ and $5k-1$ mod $6k-1$. – Will Orrick Dec 21 '18 at 07:11
  • To remove the first element from each sequence one can change the requirement $m\ge0$ to $m\ge1$ and replace $m$ with $m-1$ in the equation $6N=(6k+1)(6m+5)-5$. Then the conditions for membership in the sequences $2k-1$ and $2k$ become similar: $6N+1=(6k\pm1)(6m\pm1)$ and $6N+5=(6k\pm1)(6m\mp1)$. One concludes that $N$ is present in at least one sequence (with first element omitted) if and only if at least one of $6N+1$ and $6N+5$ is composite. – Will Orrick Dec 21 '18 at 07:47
  • @WillOrrick, thank you, I'll take a look at making appropriate changes later, when I have more time to think. Alternatively, if the necessary changes are easy and obvious, feel free to edit them in yourself. – Barry Cipra Dec 21 '18 at 13:39
  • I've added the information from my comments. Hope it's OK. – Will Orrick Dec 22 '18 at 14:34
  • @WillOrrick, it looks great. Thank you! – Barry Cipra Dec 23 '18 at 02:59
0

Since there are multiple solutions possible, you cannot just have one function. It is possible however to check if any number is part of a particular pattern. A pattern is described by three numbers. For computational simplicity, I will choose $a_{n,0}$ the first element of series $n$, the first step $t_n$, and the sum of the steps as $s_n$. A number $x$ is in series $n$ if either $(x-a_{n,0})$ or $(x-a_{n,0}-t_n)$ is divisible by $s_n$.

So now the problem simplifies to calculating $a_{n,0}$, $s_n$, and $t_n$ as functions of $n$. The first element can be written as $$a_{n,0}=\left\lfloor\frac n2\right\rfloor$$

For $t_n$ we can see a similar pattern $$t_n=4\left\lfloor\frac {n+1}2\right\rfloor$$ Finally, the second step is $2a_{n,0}+1$, so $$s_n=4\left\lfloor\frac {n+1}2\right\rfloor+2\left\lfloor\frac n2\right\rfloor+1$$

Andrei
  • 37,370