Number of 2-electron integrals Consider 2-electron integrals over real basis functions of the form
$$
(μν|λσ)=∫dr⃗_1dr⃗_2ϕ_μ(r⃗_1)ϕ_ν(r⃗_1)r^{−1}_{12}ϕ_λ(r⃗_2)ϕ_σ(r⃗_2)
$$
I am told that for a basis set of size $K=100$, there are $12,753,775$ unique 2-electron integrals of this form.
Symmetry considerations mean that we have less than $K^4$ unique integrals, since we can exchange electrons and also exchange the basis functions for each electron without changing the value of the integral.
How could one work out the number of unique integrals?
I didn't understand very well this:
Number of unique 2-electron integrals
And I found that the number of 2-electron integrals is equal to 
$$
\frac{1}{8}n(n+1)(n^2+n+2),\hspace{3mm}\text{for}\hspace{4mm} n=100 \hspace{4mm}\Longrightarrow \hspace{4mm}12,753,775\hspace{4mm} \text{integrals}
$$
but I don't know how to explain it.
 A: Here I want to discuss this answer by Luboš Motl in detail:
Basically, you have 4 indices for your wavefunctions, out of which $k=1,\dots,4$ can be different. There are ${n \choose k}$ different possibilities to choose $k$ different values from $n$ choices.


*

*If you have 4 different indices, there are 3 possibilities to divide them into pairs.

*For 3 different indices, there are 3 possibilities to chose the one which is used twice, and two possible divisions to pairs.

*If there are two different indices, either 3 are equal, for which there are two possibilities; or there are 2 pairs which are equal and there are two possibilities to divide them.

*Finally, if all indices are equal, there is only 1 possibility.


In total, the number of unique integrals is
$$3\cdot{100\choose4}+3\cdot2\cdot{100\choose3}+(2+2)\cdot{100\choose2}+{100\choose1} \,,$$
which is the answer of Luboš Motl.
You can obtain your formula by just expanding the binomial coefficients, e.g., ${n\choose 4}=n(n-1)(n-2)(n-3)/24$ and combining the different terms.
A: $\Longrightarrow$ Four different indices:  $(\mu\neq\nu\neq\lambda\neq\sigma)$
$$
(\mu\nu|\lambda\sigma)\neq(\mu\lambda|\nu\sigma)\neq(\mu\sigma|\nu\lambda)\hspace{4mm}\Longrightarrow\hspace{4mm}3\cdot\binom{100}{4}
$$
$\Longrightarrow$ Three different indices:  $(\mu\neq\nu\neq\lambda=\sigma)$
$$
(\mu\mu|\nu\lambda)\neq(\nu\nu|\mu\lambda)\neq(\lambda\lambda|\mu\nu);\\(\mu\nu|\mu\lambda)\neq(\nu\mu|\nu\lambda)\neq(\lambda\mu|\lambda\nu)\hspace{4mm}\Longrightarrow\hspace{4mm}6\cdot\binom{100}{3}
$$
$\Longrightarrow$ Two different indices:  $(\mu\neq\nu=\lambda=\sigma)$
$$
(\mu\mu|\nu\nu)\neq(\mu\nu|\mu\nu);\\(\mu\mu|\mu\nu)\neq(\nu\nu|\nu\mu)\hspace{4mm}\Longrightarrow\hspace{4mm}4\cdot\binom{100}{2}
$$
$\Longrightarrow$ All indices are equal:  $(\mu=\nu=\lambda=\sigma)$
$$
(\mu\mu|\mu\mu)\hspace{4mm}\Longrightarrow\hspace{4mm}1\cdot\binom{100}{1}
$$
Then
$$
3\cdot\binom{100}{4}+6\cdot\binom{100}{3}+\cdot\binom{100}{2}+1\cdot\binom{100}{1}=12,753,775
$$
