Let p be a prime satisfying the condition of the problem. By assumption, there is a positive integer A such that 3p−1−1=pA2.
It is clear that p=2 is a solution. Now, we consider p>2. Put p−1=2k, one has (3k−1)(3k+1)=pA2. Since (3k−1,3k+1)=2, it follows that there are positive integers B and C such that either
3k−1=2pB2,3k+1=2C2
or
3k−1=B2,3k+1=2pC2.
But, the first case cannot hold since 2C2=3k+1≡1(mod3), we get C2≡2(mod3) which is impossible.
For the second case, if k is odd then 4∣3k+1=2pC2, hence 2∣C (since p is odd). This turns out to be that 3k+1=2pC2 is divisible by 8 which contradicts to 3k+1≡4(mod8) (since k is odd). Thus, k must be even. Put k=2m, then
2B2=3k−1=(3m−1)(3m+1).
Again, since (3m−1,3m+1)=2, there are positive integers D,E such that either
3m−1=E2,3m+1=2D2
or
3m−1=2E2,3m+1=D2.
As above, the equality 3m+1=2D2 leads to a contradiction. Hence, 3m+1=D2, that is
3m=D2−1=(D−1)(D+1).
Therefore, there are non-negative integers t>s such that D−1=3s and D+1=3t. This gives,
2=(D+1)−(D−1)=3t−3s=3s(3t−s−1).
This happens if and only if 3s=1 and 3t−s−1=2, i.e. s=0 and t=1, we find that p=5 (satisfied).
In conclusion, p=2;5. □