## Sum of first n factorials

In my latest number theory assignment, there was a recurrence relation defined by

$\displaystyle a_1=1,\ \ a_2=3, \ \ a_{n+2}=(n+3)a_{n+1}-(n+2)a_{n} \ \ \ \forall n\in\mathbb{N}$

Letting $b_n=a_{n}-a_{n-1}$ we can manipulate the recurrence relation to solve for $b_n$ and then solve back for $a_n$. The result is that

$\displaystyle a_n=\sum_{j=1}^n j! \ \ \ \forall n\in\mathbb{N}$

So it is pretty neat fact that sum of first n factorials satisfies reasonably simple recurrence relation. Now, let’s take a look at few values of $a_n$.

$\displaystyle a_1=1!=1$

$\displaystyle a_2=1!+2!=3$

$\displaystyle a_3=1!+2!+3!=9$

$\displaystyle a_4=1!+2!+3!+4!=33$

$\displaystyle a_5=1!+2!+3!+4!+5!=153$

$\displaystyle a_6=1!+2!+3!+4!+5!+6!=873$

$\displaystyle a_7=1!+2!+3!+4!+5!+6!+7!=5913$

One might ask what interesting properties these numbers might have. Probably lots!

Observe that $a_1=1$ and $a_3=9$ are perfect squares. For what other values of $n$ the number $a_n$ is perfect square? It turns out that these are the only ones, and in particular $a_n$ is not perfect square for every $n\ge 4$. Proving this is actually easier than it sounds. When I first saw this problem, I tried to show that $a_n$ is strictly between two consecutive squares (which, by the way, is very useful trick in problems like this), but that didn’t go too well. There is much easier approach, as outlined below.

Let’s take a look at the last digit of $a_n$. It appears that $a_n$ ends with digit $3$ for $n\ge 4$. How can we prove this? Well, we know $a_4$ ends with $3$, (namely $a_4=33$). But now observe that for $j\ge 5$, the term $j!$ will end with $0$, because product will contain both $2$ and $5$. Hence, for $n\ge 5$,

$\displaystyle a_n=\sum_{j=1}^n j!=33+\sum_{j=5}^n j!$

which therefore ends with digit $3$. It is easy to check that no perfect square can end with digit $3$ (namely by checking all squares mod $10$). This shows that $a_n$ is not perfect square for $n\ge 4$. Indeed, the solution didn’t require anything higher than basic high school math!

As a bonus, the reader of this blog can try figuring it out when the sum of first $n$ factorials is perfect integer power.

This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

### 3 Responses to Sum of first n factorials

1. Huseyn says:

Thanks a lot mate. Keep it up. Best wishes from homeland, Azerbaijan.

• Hi Huseyn,
Thanks for the comment. I did not forget that we went to the same high school! 🙂

2. Derek O says:

Great proof! What about a cube?