4

I am looking for the number of integer solutions $(x, y)$ to the equation $$x^y \equiv y^x \mod p, \qquad 0 < x, y < p,$$ where $p$ is a prime number. However, even for small prime, I am having trouble finding all solutions.

In general, I know that $(2k, p - 1)$ and $(p - 1, 2k)$ are solutions due to Fermet's Little Theorem. I also know that $(k, k)$, $(2, 4)$, and $(4, 2)$ are solutions since they are also integers solutions to the equation $x^y = y^x$. But I'm having trouble characterising the other solutions.

For example, for $p = 13$, how would I be able to determine that $(7, 11)$ and $(3, 9)$ (and $(11, 7)$ and $(9, 3)$) are also solutions?

Wang Kah Lun
  • 10,240
byhill
  • 75
  • it might help if you pick a primitive root $g$ and write $x = g^a, y = g^b,$ and your equation becomes: $$g^{ag^b-bg^a}\equiv 1\bmod p\implies ag^b-bg^a\equiv 0\bmod p$$ – dezdichado Jul 01 '22 at 20:13
  • 6
    The most natural way to describe the solutions is as (a set of ordered pairs of) residue classes modulo $p(p-1)$. This is because the exponents are periodic modulo $p-1$ (by Fermat's little theorem) while the bases are periodic modulo $p$. In particular, the last congruence of @dezdichado's comment should be modulo $p-1$, not modulo $p$. – Greg Martin Jul 01 '22 at 20:23

1 Answers1

5

This is more complicated than it looks because solutions to $x^y\equiv y^x\bmod p$ (with $p$ prime) are actually not defined $\bmod p$. They are defined $\bmod p(p-1)$ because the power varies with the residue of the exponent $\bmod p-1$, not $\bmod p$. For instance with $p=13$, $2^5\not\equiv5^2$ but $2^{18}\equiv18^2\bmod13$; so instead of determining whether $\{2,5\}\bmod13$ is a solution we say that $\{2,5\}\bmod156$ is not a solution whereas $\{2,18\}\bmod156$ is one.

This means even with a prime modulus seemingly as small as $13$, the solution process gets a bit unwieldy. I shall explore the solution with a smaller prime, $p=5$, to illustrate what is involved and give an idea of the multitude of solutions that emerge. The discussion here is limited to nonzero residues $\bmod 5$ because zero residue gives problems with the peculiar behavior of $0$ as both a base and an exponent. If we require strictly positive bases and exponents, then all pairs where both elements are zero $\bmod 5$, such as $\{5,10\}\bmod 20$, are added to the solution set derived below for the other residues.

We start by considering solutions for the case $x=1$, meaning $x\equiv1\bmod20$. We set up the equation

$1^y\equiv y^1\bmod5$

and try each nonzero residue $\bmod 5$ for $y$ on the right side. This may be paired with appropriate residues $\bmod4$ for $y$ on the left side to give solutions for $y\bmod20$. Thus $y\equiv1\bmod5$ on the right turns out to work with any residue $\bmod 4$ on the left, and we identify four solutions for $\{x,y\}$:

$\{x,y\}\in\{\{1,1\},\{1,6\},\{1,11\},\{1,16\}\}\bmod 20.$

The other possible residues $\bmod 5$ on the right side can give no more solutions because the left side is forced to $1\bmod 5$.

For $x\equiv2\bmod20$ the equation becomes:

$2^y\equiv y^2\bmod5.$

Now for $y\equiv1\bmod5$ we specifically need $y\equiv0\bmod4$, so we get the single solution $\{x,y\}\equiv\{2,16\}\bmod 20$. Similarly $y\equiv2,3,4\bmod5$ yield respectively $\{2,2\},\{2,18\},\{2,4\}$.

We go through all the residues for $x\bmod 20$ in this way, getting all the pairs indicated in blue for residues that are nonzero $\bmod 5$:

enter image description here

There is no mistake with residue $16\bmod 20$: every natural number $y$ other than multiples of $5$ satisfies $16^y\equiv y^{16}\bmod5$ (all the numbers end with $1$ or $6$ when we represent them in base $10$). Try it with the solution method I give above!

Oscar Lanzi
  • 39,403
  • Very interesting! [All I changed was a missing $ sign] – Mike Jul 02 '22 at 00:15
  • Side question: the "$16$ works with everything" nature in mod $5$ suggests that $m=(p-1)^2$ might be similarly special for other primes? As $m \equiv 1 \pmod p$, having it as the base should always return $1$. And since $((p-1) \mid m$, having it as the exponent always gives $1$ unless the base is $0 \pmod p$, by FLT. Do I have that correct? – Eric Snyder Jul 02 '22 at 06:42
  • Yea, $(p-1)^2$ has this property for all $p$. Good catch. – Oscar Lanzi Jul 02 '22 at 06:59