A prime number pattern

The algorithm Given a natural number $n$ define a procedure as follows:

• Generate a list of primes upto and possibly including, $n$
• Assign $Z = n$
• If $Z > 0$, subtract the largest prime from list which we haven't considered yet. Otherwise, add it to $Z$. If $n$ is prime, it is assumed accounted for by the first step.
• Repeat until all primes have been considered.

For example, take $25$. The list of primes would be $2, 3, 5, 7, 11, 13, 17, 19, 23$. Subtracting $23$ from $Z=25$, we get $Z=2$. Next, we get $Z=2-19= -17$. And so on. Consequently, $Z$ assumes the values $25, 2, -17, 0, 13, 2, -5, 0, 3, 1$.

Note: Only an example. The conjecture as stated deals with applying the algorithms on primes. However, other numbers also seem to exhibit interesting patterns.

The Pattern

• Beginning at $3$ and every other prime thereafter, following the algorithm always (seems to) land us at $1$.
• For the rest of the primes, $Z$ has a final value of either $0$ or $2$.

The problem

Please read @alex.jordan's answer as he cleverly limits the range of values $Z$ can reach (say, terminal Z, or $Z_t$) to $\{-1,0,1,2\}$. As a result, the problem is now reduced to:

• For any prime number, prove that $-1$ cannot be a terminal.

Also being discussed: here

-
but does $-17-17=0?$ – dato Jul 29 '12 at 8:56
@dato OP says that if the current value is negative, you are to add, not subtract – alex.jordan Jul 29 '12 at 9:01
This has the feel of the Collatz Conjecture although there are significant differences. – alex.jordan Jul 29 '12 at 9:03
Maybe this has nothing to do with primes. I suggest experimenting with various lists of "pseudoprimes". – Christian Blatter Jul 29 '12 at 9:15
Does your conjecture require $Z$ to be prime? It sounds like it, but it is not clear since your example uses $Z=25$. – alex.jordan Jul 29 '12 at 9:19

Here is an outline:

• No matter what $N$ you start with, it is impossible to end with $3$ or higher. The penultimate $N$-value would have either been $N=1$ (impossible, since your next step would need to have been subtracting 2) or $N=5$. Since $N$ was $5$ at some point, the prime $3$ was in the original set of primes, and this necessitates an even earlier step in the chain. The step before that would have either been with $N=2$ (again impossible, since you would have subtracted 3) or with $N=8$. And again, we have a number so large that there had to have been another prime in the original list ($5$); there had to be an earlier step; and there had to have been a point when $N$ was much larger ($13$). Since the value of $N$ is getting larger at a more than quadratic rate (summing primes grows almost like like $n^2\log(n)$) while prime values are getting larger much less quickly, this process will never have a chance to end.
• No matter what $N$ you start with, it is impossible to end with $-2$ or lower. A similar, but negative, argument applies. If we end with $-2$, then the penultimate value was either $N=0$ (not possible, since our last step would then have been adding $2$) or $N=-5$. Since $N$ is negative at this step, there must have been a previous step, where either $N=-2$ (again not possible) or $N=-8$. And this continues; we never return to an initial $N$-value that is positive, since $N$ is growing negative so quickly relative to the next largest prime.
• Since you are subtracting and adding primes (which are mostly odd) and you are starting with $N$ prime (and odd), the parity of the terminal number only depends on how many steps there are in your sequence - how many primes there are up to $N$. For example, since $N=11$ yields a prime collection $\{2,3,5,7,11\}$ with 5 elements, you will add/subtract 4 odd numbers, and end up with an odd terminal $N$-value. But with $N=13$, you will add/subtract 5 odd numbers, and end up with an even terminal $N$-value.

This explains why the terminal values of $N$ would have to alternate between something in $\{-1,1\}$ and something in $\{0,2\}$ as $N$ increments through prime values.

Your conjecture would be proved if we could rule out $-1$ as a terminal value when $N$ is prime. I've tried assuming that $-1$ is a terminal value, hoping that this led to only finitely many possible initial $N$, none of which are prime. However it appears that many $N$ lead to $-1$. The smallest are: $4, 10, 16, 22$. Perhaps it can be show that if $-1$ is terminal for $N$, then $N$ was even. But maybe someone else can take it from here.

Hope this much helps!

-
 Finding numbers for which terminal values are $-1$ still hasn't landed me an odd number. This strongly points towards there being a poof. edit: Read @alex.jordan's explanation, much better than what I posted. – Furlox Jul 29 '12 at 11:26 An elementary result that would follow if odd numbers don't have $−1$ as a terminal is that there always exists a prime between $p_2n+1$ and $−1+\sum_{i=1}^{{2n+}1}p_i$ where $p_n$ is the $n-th$ prime. For example, $-1 + 2 + 3 + 5 = 9$, if there is no prime $p$ such that \$5