Let $p$ be a prime number and $P=\{1,2,...,p-1\}$ 


In how many ways we can sum *all* the elements of $P$ in such a way that we will reach a multiple of $p$  

only when we sum the last summand? 


For example let $p=7$ .  

Clearly, $1+2+3+4+5+6$ is such a sum (In fact there exist $408$ such sums)  

 but $2+3+5+4+1+6$ is not, because already $2+3+5+4=2\cdot7$. 


We can see after a little investigation that if the total number of sums is $f(p)$,then 


$\frac{(p-1)!}{p-2}\leq f(p)\leq (p-1)!$ (equality holds iff $p=3$)


Is it possible to improve this (to find asymptotic bounds or -even better- something precise)?  

Thanks in advance!  

**EDIT** : It is possible to prove in an elementary way that for every $n\in \mathbb{N}$, $\phi(n)\mid f(n)$  

($\phi(n)$ is Euler's function)



Avoiding multiples of $p$
As I mentioned in the comments above, the number of permutations of elements $1,2,\dots,p$ (i.e., including $p$) is just by factor of $p-2$ larger than the amount in question (in fact, this is true for any odd $p$). Such permutations are now counted in <http://oeis.org/A232663>


Here is an explicit formula for the number of such permutations for a prime $p$, which I got by playing with inclusion-exclusion:


$$\sum\_{A\in M\_p} (-1)^{m+n}\cdot \frac{1}{n!} \cdot p^{n-\mathrm{rank}(A)} \cdot \prod\_{j=1}^n (c\_j-1)! \cdot \prod\_{i=1}^m \binom{r\_i}{a\_{i1}, \dots, a\_{in}},$$


where:


* $M\_p$ is the set of matrices with nonnegative integer entries that sum up to $p$, with no zero rows or columns. Size of $M\_p$ is given by <http://oeis.org/A120733>
* $A=(a\_{ij})$ is a matrix of size $m\times n$ (i.e., $m$ and $n$ are respectively the number of rows and columns in $A$);
* $c\_j = \sum\_{i=1}^m a\_{ij}$ is the sum of $j$-th column of matrix $A$;
* $r\_i = \sum\_{j=1}^n a\_{ij}$ is the sum of $i$-th row of matrix $A$;
* matrix rank is computed over $\mathrm{GF}(p)$.


The formula may not be so useful due to its complexity but it's still a nice one. But the same reason I do not post here its derivation as it would take at least a couple of pages.


The formula has been numerically tested for $p=5$ and $p=7$.


