# Is the product of two consecutive integers $1$ $\pmod n$?

Is there a simple test for $n$ to determine if there exists an integer $x$ such that $x$($x+1$) $=$ $1$ $\pmod n$. For example, $n$ $=$ $3$ and $n$ $=$ $7$, there are no integers $x$ such that $x$($x+1$) $=$ $1$ $\pmod n$. But for $n$ $=$ $5$ and $n$ $=$ $11$, there are integers $x$ such that $x$($x+1$) $=$ $1$ $\pmod n$. There are namely,

$x = 2$, $2*3$ $=$ $1$ $\pmod 5$

$x = 7$, $7*8$ $=$ $1$ $\pmod {11}$

It is confusing to find out which integers $n$ have this property. Maybe there is a special (mathematical) property these numbers have. Help is appreciated. Thanks.

• I suggest you write a program in your favourite (programming) language, and if you like, paste some of the patterns you see when you run the program. This will add context to the question, rather than us having to do the effort. – астон вілла олоф мэллбэрг Feb 13 '17 at 5:30
• Hints: 1) If this works for $n$, then it works for any prime divisor of $n$. 2) It doesn't work when $n$ is even. 3) It works modulo an odd prime $p$, iff the discriminant of $x^2+x-1$ is a quadratic residue modulo $p$. 4) Recall the law of quadratic reciprocity. 5) If it works for an odd prime $p$, it will also work modulo $p^m$ by Hensel lifting (with the exception of $p=5$, because then we have a double root). 6) If it works for all prime power factors of $n$ it will work for $n$ by the Chinese Remainder Theorem (friends call it CRT). – Jyrki Lahtonen Feb 13 '17 at 5:34
• For $(2,n)=1,$ $$n|x(x+1)\iff n|\{(2x+1)^2-1\}$$ – lab bhattacharjee Feb 13 '17 at 5:36

First we rewrite the congruence: $$4x(x+1)=4\pmod{4n}\quad\Leftrightarrow\quad (2x+1)^2=5\pmod{4n}\ .$$ Now write $y=2x+1$ and consider various cases.

• If $n$ is even then the above implies $y^2=5\pmod8$, which has no solution.

• If $5^2\mid n$ then we get \eqalign{y^2=5\pmod{25}\quad &\Rightarrow\quad 5\mid y^2\cr &\Rightarrow\quad 25\mid y^2\cr &\Rightarrow\quad 25\mid 5\cr} and again there is no solution.

• So for solutions to exist, $n$ is a product of $5$ (possibly) and prime powers $p^\alpha$ where $p$ is not $2$ or $5$. There is a solution iff $$y^2=5\pmod{p^\alpha}$$ has a solution for every such prime power, which can be proved to be equivalent to $$y^2=5\pmod p$$ having a solution for every $p\mid n$ (except $p=2,5$). Using the Legendre symbol one can show that this comes down to the following.

The congruence $x(x+1)=1\pmod n$ has a solution if and only if $n$ is a product of primes in which $5$ occurs only once (or not at all), and every other prime is congruent to $1$ or $4$ modulo $5$.

Here is a table of some low values of $n$. I have listed "ok" if the congruence has a solution, otherwise I have given a "bad" prime factor of $n$. $$\def\ok{{\rm ok}} \matrix{3&5&7&9&11&13&15&17&19&21&23&25&27&29&31&\cdots&55\cr 3&\ok&7&3&\ok&13&3&17&\ok&3&23&5&3&\ok&\ok&\cdots&\ok\cr}$$ Note that $p=5$ is "bad" for $n=25$ because it occurs twice, but it is "ok" for $n=5$ and $n=55$ because it only occurs once.

• Thanks for the brief table. That gives me an idea for another, more interesting and complex question. – J. Linne Feb 13 '17 at 6:08

You are asking when the polynomial $x^2+x-1$ has a root mod $n$. Since $x(x+1)$ is always even, clearly $n$ must be odd for such an $x$ to exist. In that case $2$ is invertible mod $n$, and so by the quadratic formula $x^2+x-1$ has a root mod $n$ iff the discriminant $5$ has a square root mod $n$.

So you are asking for what odd integers $n$ is $5$ a square mod $n$. By the Chinese remainder theorem, $5$ is a square mod $n$ iff it is a square mod $p^k$ for each prime power $p^k$ appearing in the prime factorization of $n$. For $p\neq 2,5$, $n$ is a square mod $p^k$ iff $5$ is a square mod $p$ (for instance, by Hensel's lemma). By quadratic reciprocity, $5$ is a square mod $p$ for odd $p$ iff $p$ is a square mod $5$, i.e. iff $p$ is $0,1,$ or $4$ mod $5$. The case $p=2$ does not matter since $n$ must be odd, and $5$ is a square mod $5^k$ iff $k\leq 1$.

Putting it all together, we find that $x^2+x-1$ has a root mod $n$ iff every prime factor of $n$ is $0,1,$ or $4$ mod $5$ and $25$ does not divide $n$.

As lab bhattacharjee wrote (working $\bmod n$), If $m(m+1) = 1$ then $4m^2+4m=4$ or $5 =4m^2+4m+1 =(2m+1)^2$.

Therefore, if $5$ is a quadratic residue mod $n$, there is (at least) one solution.

According to https://en.wikipedia.org/wiki/Quadratic_residue, for a prime $p$, $5$ is a quadratic residue mod $p$ if and only if $p \equiv 1, 4 (\bmod 5)$.

For composite $n$, see https://en.wikipedia.org/wiki/Jacobi_symbol.

The table there titled "Table of values" shows which $k$ have $5$ as a quadratic residue.

Clearly, the condition $x(x+1)\equiv1\pmod{n}$ cannot hold if $n$ is even (because $x(x+1)$ is itself even).

Now suppose $n$ is odd.

The OP can be reformulated as follows : find the integers $n\ge2$ such that the equation $x^2+x-\bar{1}=\bar{0}$ has at least a solution in the ring $\mathbb{Z}/n\mathbb{Z}$.

(We denote by $\bar a$ the congruence class of $a$ mod. $n$)

Note that $\bar2$ is invertible in that ring (because $gcd(2,n)=1$).

The discriminant of this quadratic equation is $\Delta=\bar5$ and the question becomes : find the integers $n\ge2$ such that $\bar5$ is a square.

The answers is given by the Legendre symbol. For example, si $n$ is an odd prime and $n\neq5$, then :

$$\left(\dfrac{5}{n}\right)=(-1)^{\left\lfloor\frac{n+2}5\right\rfloor}$$

In the general case, we can use de quadratic reciprocity law to compute $\left(\dfrac{5}{n}\right)$ and decide it is \$1* or not