Three 3-digit positive base N integers

**P**,

**Q** and

**R**, each with no leading zeroes and having the restriction

**P** <

**Q** <

**R**, are such that:

**Q** is the arithmetic mean of **P** and **R**, and:
**P**, **Q** and **R** can be derived from one another by **cyclic permutation** of digits.

Determine all possible positive integer values of N < 30 for which this is possible.

1) Let p (base N) = abc

q (base N) = bca

r (base N) = cab

where a < b < c < N

2) p + r - 2q = 0,

so (c + a - 2b)*N*N + (a + b - 2c)*N + (b + c -2a) = 0

3) Since the first two terms are multiples of N, then (b + c - 2a) must be also.

But a < b < N and a < c < N, so 0 < (b + c - 2a) < 2N

So (b + c - 2a) = N

4) Substituting gives

(c + a - 2b)*N*N + (a + b - 2c)*N + N = 0

Dividing by N, gives

(c + a - 2b)*N + (a + b - 2c + 1) = 0

Since the first term is a multiple of N, (a + b - 2c + 1) must be also.

But a < c < N and b < c < N, so 0 > (a + b - 2c + 1) > -2N

So (a + b - 2c + 1) = -N

5) Taking the two equations

(b + c - 2a) = N

(a + b - 2c + 1) = -N

and solving for b and c in terms of a and N

Gives:

b = a + ( N - 1)/3

c = a + (2N + 1)/3

6) c < N if and only if

a + (2N + 1)/3 < N

3a + (2N + 1) < 3N

a < (N - 1)/3

7) In order for b and c to be integers, N = 1 mod 3

And in order for a > 0, N must >= 7

So, N can be 4 + 3k where k = 1,2,3, etc.

and a can take any value between 1 and k