We will show that the number sought is n−1 for n=4 and 2 if n=4.
For n=3 and n=4, it can be easily verified that the answer is 2. Suppose now that n≥5. Denote by aXY the number written on segment XY.
If we label the vertices of the regular polygon as A1,A2,…,An and set aAiAj=∣i−j∣ for all i=j, then the condition of the problem is satisfied, so the number sought for is at most n−1.
To prove equality, suppose by contradiction that the number sought for is at most n−2. Let d be the greatest value John writes on some segment, and let A,B be vertices such that aAB=d. Suppose d is written on the segment with minimal distance between the vertices among all segments with value d.
We make the following two observations:
1. There do not exist three vertices A1,A2,A3 such that aAA1=aAA2=aAA3 (otherwise, it would follow that aA1A2=aA1A3=aA2A3, which is impossible because the sum rule, according to the hypothesis, would no longer be valid for triangle A1A2A3).
2. For any point X different from A and B, we have d=aAX+aBX since d is maximum; in particular, aAX<d.
Since, by assumption, there are at most n−2 distinct values, the pigeonhole principle implies that there exist points C and D such that aAC=aAD=x, with x<d (according to Observation 2).
We observe that the rule for writing the numbers on segments implies: in triangle ACD we have aCD=2x; in triangle ABD we have aBD=d−x; in triangle ABC we have aBC=d−x. Therefore, from triangle BCD, we obtain that 2x=(d−x)+(d−x), hence x=2d (in particular, d is even).
Now, looking at the n−2 numbers on the segments emerging from A, we can see that the only value that repeats is 2d (as shown in the previous paragraph) and it cannot appear three times (by Observation 1). Therefore, there are n−2 distinct numbers, and according to the assumption, these must be all the numbers used by John.
Since n≥5, there exists a vertex E different from the vertices A,B,C,D. Let y=aAE=2d. Since aBE=d−y, it follows that d−y appears among the n−2 values on the segments emerging from A. Without loss of generality, we may assume that y>2d because max(y,d−y)>2d.
We look at triangle ACE and observe that aCE∈{y+2d,y−2d}. Since d is the maximum, and y+2d>d, it follows that aCE=y−2d, and similarly, aDE=y−2d.
Finally, looking at triangle CDE, we have aCD=2(y−2d)<d, but also aCD=2⋅2d=d, a contradiction. (In triangle ACD we have aAC=aAD=2d, hence CD=d)
Therefore, there cannot be only n−2 values, which implies that the required number is n−1.