Solution:
Note that the divisibility condition is symmetrical in m and n. In other words: If Jana can cross over from island m to island n, she can also go the other way. Let us define a graph G as follows: Each of the islands 1,2,…,p represents a vertex and we draw an edge between two vertices m and n if and only if
p∣(m2−n+1)(n2−m+1)
The edges of our graph now exactly represent between which pairs of islands Jana can travel, so it's easy to see that Jana can travel to every island if and only if G is connected.
This insight motivates us to count the number of edges in G, because if we can show that there are less than p−1 edges, G has to be disconnected! By the formula
∣E∣=21v∈V∑deg(v)
it is enough to know the number of vertices of every possible degree. The degree of a fixed vertex m is the number of distinct n∈{1,2,…,p} such that
(m2−n+1)(n2−m+1)≡0(modp)
Obviously, there is exactly one choice for n such that m2−n+1≡0(modp), namely n≡m2+1. But what about n2−m+1≡0(modp)?
Lemma: Let p be an odd prime and a some residue modulo p. Then, x2−a≡0(modp) has
- no solutions in x for exactly 2p−1 different values of a.
- exactly one solution in x if and only if a=0.
- exactly two solutions in x for 2p−1 different values of a.
Proof of the Lemma: Note that x2≡y2 is equivalent to (x−y)(x+y)≡0 or in other words y≡±x(modp).
Hence, the squares of 1,…,2p−1 are all distinct modulo p and they are equal to the squares of p−1,…,2p+1, respectively. This gives us 2p−1 values of a such that there are two solutions in x. The only residue left is 0, which gives us a unique choice of a with exactly one solution in x. The remaining 2p−1 values of a therefore admit no solutions at all.
By letting a=m−1, the Lemma tells us that there are 2p−1 different m with two solutions in n. If we assume that the conditions n2−m+1≡0(modp) and m2−n+1≡0(modp) are never satisfied at the same time (or for m=n), we would get
∣E∣=21v∈V∑deg(v)=21⋅(2p−1⋅1+1⋅2+2p−1⋅3)=p
Sadly, this is not small enough! We need to reduce the number of edges a bit more. The easiest way of doing this is by assuming that there exists a residue m such that m2−m+1≡0(modp). This corresponds to a loop in G (an edge going from m to itself), which is irrelevant for the connectivity of G. A short calculation inspired by Vieta shows that m2−m+1≡0(modp) implies (1−m)2−(1−m)+1≡0(modp), so as long as m≡1−m(modp), we have two loops, from which we conclude that G is disconnected.
Let us now prove that there are infinitely many primes p such that there exists a residue m satisfying m2−m+1≡0(modp): Let m be the product of the first k primes and let p be a prime factor of m2−m+1. In particular, p is not equal to the first k primes and so there are infinitely many such p. If m≡1−m(modp) then m≡2p+1(modp). However, in this case we must have
(2p+1)2−2p+1+1=4p2+3≡0(modp)
which is equivalent to p=3. This shows that for all such p>3 that we constructed, G is indeed disconnected.
Alternative arguments (inspired by Joel/Mathys): Instead of introducing a simple undirected graph, we introduce a not necessarily simple directed graph where the edge points from m to n if p∣m2−n+1 and from n to m if p∣n2−m+1. The directions are actually completely irrelevant for Jana's travel plans but they allow us to count the edges more elegantly:
For every m there is exactly one value of n such that m2−n+1≡0(modp). This means that each of the p vertices has one edge pointing away from it, and therefore we have p edges in total.
To show that the graph is not connected, we will explicitly find two vertices of G which will have loops: Let p≡1(mod3), in particular, p is odd and so p−1 is divisible by 6. Take a primitive root a modulo p. For m=a6p−1 we have
m6−1≡0(modp)⇔(m2−m+1)(m+1)(m3−1)≡0(modp)⇒m2−m+1≡0(modp)
because, since a is a primitive root, m+1 and m3−1 cannot be divisible by p. But the same calculation can be done with m=a65(p−1), so we found two loops for infinitely many p (Dirichlet) and we're done!