A Prime Number Generator

Take the first n prime numbers, 2, 3, 5, …, pn, and divide them into two groups in any way whatever. Find the product of the numbers in each group, and call these A and B. (If one of the groups is empty, assign it the product 1.) No matter how the numbers are grouped, A+B and \left |A-B  \right | will always turn out to be prime numbers, provided only that they’re less than p_{n+1}^{2} (and greater than 1, of course). For example, here’s what we get for (2, 3, 5) (where p_{n+1}^{2} = 72 = 49):

2 × 3 + 5 = 11
2 × 5 + 3 = 13
2 × 5 – 3 = 7
3 × 5 + 2 = 17
3 × 5 – 2 = 13
2 × 3 × 5 + 1 = 31
2 × 3 × 5 – 1 = 29

In More Mathematical Morsels (1991), Ross Honsberger writes, “For me, the fascination with this procedure seems to lie to a considerable extent in the amusement of watching it actually turn out prime numbers; I’m sure I only half believed it would work until I had seen it performed a few times.”

It makes sense if you think about it. Each of the first n prime numbers will divide either A or B but not the other, so it will fail to divide either A+B or \left |A-B  \right |. That means that any prime divisor of A+B or \left |A-B  \right | must be at least as big as p_{n+1}, and if there were more than one of them, the number would amount to at least p_{n+1}^{2}, putting it outside the limit. So for A+B or \left |A-B  \right | between 1 and p_{n+1}^{2}, it must itself be a prime number p such that pn+1p < p_{n+1}^{2}.