       "Substract one and add one" algorithm

• To: mathgroup at smc.vnet.net
• Subject: [mg59041] "Substract one and add one" algorithm
• From: "Gilmar" <gilmar.rodriguez at nwfwmd.state.fl.us>
• Date: Wed, 27 Jul 2005 01:25:40 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```Dear Mathematica Users Forum Friends:

I want to build a function h[n] that does the following:

For n even greater and equal than 4:

Case 1: If m=n/2 is prime then h[n]={n/2,n/2}. Done.

Case 2: If m =n/2 is not prime; let p=n/2 -1 and q=n/2+1.

If both p, and q are prime then,
h[n]={p,q}. Done.

If either one or both p and q are not prime;
let p =p-1, and q=q+1.

If both p, and q are prime then
h[n]={p,q}. Done.

If either one or both p and q are not prime;
let p =p-1, and q=q+1.

etc.

I want to test empirically that a value h[n] = {p[k],q[k]}
(for an appropriate integer k) exists.

A few examples:

n=4
n/2=2 is prime; so h={2,2}.

n=6
n/2=3 is prime; so h={3,3}.

n=8 is not prime; so p=n/2 -1 =3 is prime and q=n/2+1=5 is prime;
so h={3,5}.

n=10
n/2=5 is prime; so h={5,5}.

n=12
n/2=6 is not prime; so p=n/2-1=5 is prime and q=n/2+1=7 is prime;
so h={5,7}.

n=14
n/2=7 is prime; so h={7,7}.

n=16
n/2=8 is not prime;
so p=n/2-1=7 is prime but, q=n/2+1=9 is not prime,
so p=7-1=6 is not prime, and q=9+1=10 is not prime,
so p=6-1=5 is prime, and q=10+1=11 is prime,
so h={5,11}.