For an integer N, we will choose a permutation ${P_1,P_2,\cdots,P_N}$ of ${1,2,\cdots,N}$.
Then, for each $i =1,2,\cdots,N$, let $M_i$ be the remainder when $i$ is divided by $P_i$.
Find the maximum possible value of $M_1+M_2+\cdots+M_N$.
Input is given from Standard Input in the following format:
1 | N |
Print the maximum possible value of $M_1+M_2+\cdots+M_{N}$.
1 | 2 |
1 | 1 |
When the permutation ${P_1,P_2}={2,1}$ is chosen, $M_1+M_2=1+0=1$.
1 | 13 |
1 | 78 |
1 | 1 |
1 | 0 |
The biggest answer is that after the operation the number can remain it self. To make this satisfy the most, you just need to mode this number by this number plus 1. $ 1 \space mod \space 2, 2,\space mod \space 3, \cdots, n-1 \space mod \space n$ . So The left number $n$ is mode by $1$ which is always equal to $1$ .
And you can easily find that the answer is
$$
1+2+3+\cdots+(n-1)+1 \= \frac{(1+(n-1))(n-1)}{2} + 1 \= \frac{n(n-1)}{2} + 1
$$
1 |
|