I can see that this works for any integer $n$, but I can't figure out why this works, or why the number $42$ has this property.

6Hint: Fermat's Little Theorem. – Arturo Magidin Feb 15 '11 at 06:13

5Hint #2: Chinese Remainder Theorem. – Pete L. Clark Feb 15 '11 at 06:19

So I would say p=7 and $n^{(p1)}= n^6 \cong 1(mod 7)$, but I'm confused here because $42 \ncong 1(mod 7)$ – Feb 15 '11 at 06:21

2So you have $n^6\equiv 1\pmod{7}$, but this implies $n^7\equiv n\pmod{7}$. So $7n^7n$. In general, $n^p\equiv n\pmod{p}$ for a prime $p$. By the same token, $n^7\equiv (n^3)^2\cdot n\equiv n^3\equiv n\pmod{3}$ by FlT, so $3n^7n$. It remains to show $2n^7n$, and then you'll be done by the two hints above. – yunone Feb 15 '11 at 06:32

@Katie: A simplest proof would be to recognize $2$ and $3$ divides the number and then argue out by Fermat's theorem why $7$ divides $n^7n$. – Feb 15 '11 at 06:32

Try $p=7$ and $p=6$ separately. – Yuval Filmus Feb 15 '11 at 06:33

1@Yuval: $p=6$ ? :) – lhf Feb 15 '11 at 12:26

With a calculator trying some random numbers ! seriously that is the most easiest way to prove it !!! – omeid Feb 15 '11 at 12:22

Try random numbers does not prove anything. But trying all numbers from 0 to 41 does. However, it does not tell us *why* it works. – lhf Feb 15 '11 at 12:25

@lhf: You know it.But i just only look at the question title. :D – omeid Feb 15 '11 at 12:29

oh, you mean "any" vs "every". Right! – lhf Feb 15 '11 at 12:31

42 is actually the largest modulus that works for this case. See http://math.stackexchange.com/questions/164524/largestmodulusforfermattypepolynomial. – lhf Jun 29 '12 at 12:01

1It works because $42=6(6+1)$ and Little Fermat, but I like to believe it works because it is the answer to the life, the universe and everything. – chubakueno Sep 01 '13 at 22:22

@chubakueno. Recall that in the Hitchhiker's Guide To The galaxy, it is revealed that $6\times 9=42.$ After that, the rest is easy.$:\cdot ()$ – DanielWainfleet May 12 '16 at 02:23
8 Answers
Problems like this appear frequently here. There are a couple of standard approaches. One is to use Fermat's little theorem, which says that if $p$ is a prime number, then $n^pn$ is divisible by $p$ for all $n$.
Since $42=2\times 3\times 7$, what we need to do is to check that 2, 3, and 7 divide $n^7n$, no matter what $n$ is.
That 7 does is direct from Fermat's little theorem.
The theorem also ensures that 3 divides $n^3n$. Now: $$n^7n=n(n^61)=n((n^2)^31)=n(n^21)(n^4+n^2+1)=(n^3n)(n^4+n^2+1),$$ so 3 indeed divides $n^7n$.
Finally, $n$ and $n^7$ always have the same parity, so $n^7n$ is even.
We can actually argue without Fermat's little theorem in this case. An approach that only requires patience is as follows: The idea is to factor the polynomial $x^7x$ and then analyze the result when $x=n$ is an integer. (This is a trick that Bill Dubuque suggests sometimes in his solutions.)
We have: $x^7x=x(x^61)=x(x^3+1)(x^31)=x(x+1)(x^2x+1)(x1)(x^2+x+1)$. When $x=n$, we have $$ n^7n=(n1)n(n+1)(n^2n+1)(n^2+n+1). $$ Now we analyze this prime by prime, as before. Note that one of $n$ and $n1$ is always even, so the product is even. Also, of 3 consecutive numbers, such as $n1,n,n+1$, one is always divisible by 3, so it only remains to verify divisibility by 7.
We may assume that $n=7k+b$ where $b=\pm2$ or $\pm3$, since otherwise $(n1)n(n+1)$ is a multiple of 7. In that case, $n^2\equiv 4$ or $2\pmod 7$, and one of $n^2+n$, $n^2n$ is $\equiv 6\pmod 7$, so $(n^2n+1)(n^2+n+1)$ is a multiple of 7.
The disadvantage of this approach over the previous one, of course, is the need to analyze different cases. Fermat's little theorem allows us to analyze all cases simultaneously, which typically (as here) results in a much faster approach.
If you are comfortable with the method of induction, this gives us a way of verifying divisibility by 7 which is not without some elegance (divisibility by 2 and 3 is probably best approached as before). Note that $(n)^7(n)=(n^7n)$, so we may as well assume that $n\ge 0$. If $n=0$ it is obvious that 7 divides $n^7n$.
Suppose then that $7n^7n$, and argue that $7(n+1)^7(n+1)$. For this, actually expand $(n+1)^7$ using the binomial theorem: $$ (n+1)^7=n^7+7n^6+{7\choose 2}n^5+{7\choose 3}n^4+\dots+1.$$ The point is that $${7\choose k}=\frac{7!}{k!(7k)!}$$ is obviously divisible by 7 as long as $k\ne0,7$, so (modulo 7) we have that $(n+1)^7(n+1)\equiv (n^7+1)(n+1)=(n^7n)$. Now we invoke the induction hypothesis, that precisely says that the latter is divisible by 7, and we are done.
Of course, exactly the same inductive argument gives us a proof of Fermat's little theorem: $pn^pn$ for any $p$ prime and any integer $n$.
 75,806
 9
 204
 327

To prove that $3$ divides, you can observe that $n^7n=n^7n^5+n^5n^3+n^3n$ – N. S. Jun 29 '12 at 15:42
It is a special case of the following globalform of little Fermat. $ $ For $\rm\, a,k,n\in\mathbb N$ with $\rm\ a,k > 1$
$\rm\qquad d\ \ n^k\! \! n\ $ for all $\rm\:n\:$ $\rm \iff\ d\:$ is squarefree, and $\rm\ p\!\!1\ \ k\!\!1\ $ for all primes $\rm\:p\:\:d$
So for $\rm\: a = 42 = 2\cdot 3\cdot 7\ $ we deduce: $\rm\ \ 42\ \ n^k\!n\ $ for all $\rm\,n\! \iff\! 6\ \ k\!\!1,\,$ e.g. $\rm\,k\!=\!7$.
For the simple proof and further discussion see Korselt's criterion for Carmichael numbers (here we need only the easy direction $(\Leftarrow))$, or see my 2009/04/10 sci.math post.
Here is another useful variation:
Theorem $\ $ Suppose that $\ m\in \mathbb N\ $ has the prime factorization $\:m = p_1^{e_{1}}\cdots\:p_k^{e_k}\ $ and suppose that for all $\,i,\,$ $\ \color{#0a0}{e_i\le e}\ $ and $\ \phi(p_i^{e_{i}})\mid f.\ $ Then $\ m\mid \color{#0a0}{a^e}(a^f1)\ $ for all $\: a\in \mathbb Z.$
For $\,m = 2\cdot 3\cdot 7\,$ we have $\,e_i=1,\,$ $\,\phi(p_i^{e_i}) = 1,2,6\mid f\!=\!6,\,$ so $\,m\mid a(a^61)$ for all $\,a\in \Bbb Z$
You can find many illuminating examples in other questions here, e.g. below
$\qquad\qquad\quad$ $24\mid a^3(a^21)$
$\qquad\qquad\quad$ $40\mid a^3(a^41)$
$\qquad\qquad\quad$ $88\mid a^5(a^{20}\!1)$
$\qquad\qquad\quad$ $6p\mid a\,b^p  b\,a^p$
 257,588
 37
 262
 861

1Very nice application of Fermat's Little Theorem's globalform (I had never seen it). However, the link to your proof takes me nowhere... – Dr. Mathva May 07 '19 at 13:20

@Dr.Mathva I added a local link (alas Google continues to break links to its usenet newsgroup archive). – Bill Dubuque May 07 '19 at 14:06
Combinatorial Polynomial Approach
Since $$ \begin{align} n^7n &=5040\binom{n}{7}+15120\binom{n}{6}+16800\binom{n}{5}+8400\binom{n}{4}+1806\binom{n}{3}+126\binom{n}{2}\\ &=42\left[120\binom{n}{7}+360\binom{n}{6}+400\binom{n}{5}+200\binom{n}{4}+43\binom{n}{3}+3\binom{n}{2}\right] \end{align} $$ Therefore, we have that for all $n\in\mathbb{Z}$, $$ 42\mid n^7n $$
Little Fermat Approach
Little Fermat Theorem says $$ n^7\equiv n\pmod7 $$ and since $7\equiv1\pmod2$ $$ n^7\equiv n\pmod3 $$ and since $7\equiv2\pmod1$ $$ n^7\equiv n\pmod2 $$ Thus, $$ n^7\equiv n\pmod{42} $$
 326,069
 34
 421
 800

1+1. But I have a question: how do you know that $$n^7n =5040\binom{n}{7}+15120\binom{n}{6}+16800\binom{n}{5}+8400\binom{n}{4}+1806\binom{n}{3}+126\binom{n}{2}$$? Is there some special formula or theorem for this expansion? I saw a similar one for the case $30\mid n^5n$ – Dr. Mathva May 04 '19 at 15:34

1If we know the values of $f(n)=n^7n=\sum\limits_{k=0}^7a_k\binom{n}{k}$ for $n=0$ to $n=7$, it is very easy to compute the coefficients $a_k$ since for $n\lt k$, $\binom{n}{k}=0$. Since $f(1)=f(0)=0$, we get $a_1=a_0=0$. Since $f(2)=126$, we get $a_2=126$. Since $f(3)=2184$, $a_3=2184126\binom{3}{2}=1806$. Since $f(4)=16380$, $a_4=163801806\binom{4}{3}126\binom{4}{2}=8400$. etc. – robjohn May 04 '19 at 16:04


Sorry for asking again, but I've just noticed there's one last thing I don't understand. You claim "If we know the values of $\displaystyle f(n)=n^7n=\sum^7_{k=0}a_k\binom{n}{k}$ [...]". How can we, however, prove that $f$ can be represented as this sum? – Dr. Mathva May 11 '19 at 20:52

If you look at the method for computing $a_n$, you will see that as long as $f(n)$ is integral for $8$ consecutive integers $n$, we get the $8$ coefficients for this sum. – robjohn May 12 '19 at 00:52
There are many equivalent ways of proving it.
First observe that $42$ divides a number iff $2,3$ and $7$ divides the number.
(Since $42 = 2 \times 3 \times 7$ and $\gcd(2,3) = \gcd(3,7) = \gcd(2,7) = 1$)
Divisibility by $2$:
Clearly, $2(n^7n)$ since $n^7$ and $n$ are of the same parity.
Equivalently you could argue out that $2(n^2n)$ directly from Fermat's little Theorem. (This is an overkill of Fermat's Little Theorem.)
Divisibility by $3$:
$n^7n = n(n^61) = n(n^21)(n^4+n^2+1)=n(n+1)(n1)(n^4+n^2+1)$.
$3n$ or $3(n1)$ or $3(n+1)$ and hence $3(n^7n)$.
Equivalently you could argue out that $3(n^3n)$ directly from Fermat's little Theorem.
Divisibility by $7$:
Note that $n$ can be either $7k$ or $7k \pm 1$ or $7k \pm 2$ or $7k \pm 3$.
If $n=7k$ or $n=7k \pm 1$, we are again done since then $7n$ or $7(n+1)$ or $7(n1)$ and hence $7(n^7n)$.
If $n=7k \pm 2$, then $n^2 = (7k \pm 2)^2 = 7m + 4$ and $n^4 = (7m+4)^2 = 7l+2$. Hence $n^4 + n^2 + 1 = 7l+2 + 7m + 4 + 1 = 7(l+m+1)$ and hence $7(n^4 + n^2 + 1) \Rightarrow 7(n^7n)$.
If $n=7k \pm 3$, then $n^2 = (7k \pm 3)^2 = 7m + 2$ and $n^4 = (7m+2)^2 = 7l+4$. Hence $n^4 + n^2 + 1 = 7l+4 + 7m + 2 + 1 = 7(l+m+1)$ and hence $7(n^4 + n^2 + 1) \Rightarrow 7(n^7n)$.
Hence, $7(n^7n)$.
Equivalently you could argue out that $7(n^7n)$ directly from Fermat's little Theorem.
Therefore, we have that $2(n^7n)$ and $3(n^7n)$ and $7(n^7n)$, $\forall n \in \mathbb{N}$.
Hence, $42(n^7n)$, $\forall n \in \mathbb{N}$.
As $42=2.3.7$. Therefore,we need to check that $n^7n$ is divisible by $2,3$ and 7. For divisibility by $2$, by fermat's little theorem, $n^2=n\pmod 2 \implies {(n^2)}^3.n=n^4\pmod 2=n^2\pmod 2=n\pmod 2 \implies n^7n=0\pmod2$. For divisibility by 3, $n^3=n\pmod 3\implies n^7=n^3\pmod 3=n\pmod 3 \implies n^7n=0\pmod 3$. For divisibility by 7, $n^7=n\pmod 7 \implies n^7n=0\pmod 7$. These relations implies that $42(n^7n)$.
 14,295
 2
 33
 72
Just for completeness, here is induction (just for divisibility by 7) :
Claim : $n^7  n$ is divisible by 7
Base Case: True for n = 1,2
Induction Step: Assume true for n = k. To prove true for n = k + 1.
Now, $$(k+1)^7  (k+1) = k^7 + 7k^6 + 21k^5 + 35k^4 + 35k^3 + 21k^2 + 7k + 1  k  1 \\= (k^7  k) + 7(k^6 + 3k^5 + 5k^4 + 5k^3 + 3k^2 + k)$$ We know by our assumption that $k^7  k$ is divisible by 7. Therefore, $(k + 1)^7  (k + 1)$ is divisible by 7.
This shows that $n^7  n$ is divisible by 7.
To show divisibility by 2 and 3, unfortunately, one has to fall back on some of the earlier tricks. $$n^7  n = n(n^6  1) = (n1)n(n+1)(n^2  n + 1)(n^2 + n + 1)$$ $(n1)n(n+1)$ is a product of three consecutive integers. Product of two consecutive integers is divisible by 2 and product of three consecutive integers is divisible by 3. Since, $(2,3) = 1$, product of three consecutive integers is divisible by 6. Since $(6,7) = 1$, $n^7  n$ is divisible by 42.
QED
 3,821
 18
 28

3


@Ihf, The proof shows that $n^7  n$ is divisible by both $6$ and $7$. Since $42 = 6 \times 7$ hence proved. – Aritro Shome Nov 04 '21 at 15:00
F$\ell$T$^*$ (if $p\not\vert n$, then $p\vert n^{p1}1$) $\Rightarrow$
if $2\not\vert n$, then $2\not\vert n^6$, and then $2\vert (n^6)^11$
if $3\not\vert n$, then $3\not\vert n^3$, and then $3\vert (n^3)^21=n^61$
if $7\not\vert n$, then $7\vert n^61$
so $2,3,7\vert n^7n$.
$^*$: $\ell$=little.
 665
 2
 6
 10
Just to give a different approach, we have
$$\begin{align} n^7n&=n(n^61)\\ &=n(n^31)(n^3+1)\\ &=n(n1)(n^2+n+1)(n+1)(n^2n+1)\\ &=n(n1)(n+1)(n^2+n6+7)(n^2n6+7)\\ &=n(n1)(n+1)\Big((n2)(n+3)(n+2)(n3)+7\cdot\text{quadratic in }n\Big) \end{align}$$
where the quadratic in $n$, to be explicit, is $2(n^26)+7$. What's important, though, is that $n(n1)$, being the product of two consecutive integers, is always divisible by $2$, $n(n1)(n+1)$, being the product of three consecutive integers, is always divisible by $3$, and $n(n1)(n+1)(n2)(n+3)(n+2)(n3)$, being the product of seven consecutive numbers, is always divisible by $7$.
 78,116
 7
 74
 151

could you explain how you derived the last two steps of the factorisation ? – Aritro Shome Nov 04 '21 at 15:03

@AritroShome, $n^2+n+1=n^2+n6+7$ (since $1=6+7$), and $n^2+n6=(n2)(n+3)$. Thus $(n^2+n+1)(n^2n+1)=(n2)(n+3)(n^2n+1)+7\cdot\text{quadratic in }n$. Now do the same with $n^2n+1=n^2n6+7=(n+2)(n3)+7$. I hope that makes sense. Or if you prefer, just verify that $$(n^2+n+1)(n^2n+1)=(n2)(n+3)(n+2)(n3)+7(2n^25)$$ by expanding both sides into a quartic. – Barry Cipra Nov 04 '21 at 17:26