       Re: "Substract one and add one" algorithm

• To: mathgroup at smc.vnet.net
• Subject: [mg59074] Re: "Substract one and add one" algorithm
• From: Detlef Müller at smc.vnet.net
• Date: Thu, 28 Jul 2005 02:26:38 -0400 (EDT)
• References: <dc776m\$k2h\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Gilmar wrote:
...
> 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 just assume, this comes to an end.

So simply write down, what you said as a Module:

Clear[h];
h[n_/;EvenQ[n]&&(n>=4)]:=
Module[{p=n/2,q=n/2},
While[Not[PrimeQ[p]&&PrimeQ[q]],
p=p-1;q=q+1
];
{p,q}
]

In:=
h/@{4,6,8,10,12,14,16}
Out=
{{2,2},{3,3},{3,5},{5,5},{5,7},{7,7},{5,11}}

Greetings,
Detlef

```

• Prev by Date: PlotLegend & Tick marks in MultipleListPlot
• Next by Date: Re: silly questions?