I want to simplify the following expression


$$\sum\_{1\leq a,b\leq n}\mathcal{P}(\gcd(a,b,n)),$$ where $\mathcal{P}(x)$ is the number of partitions of $x$.


It turned out this number is the top betti number of the $C\_n\times C\_n$ covering of the Hilbert scheme of $n$ points of the 2-torus. Simplifying this expression may lead to other possible ways of calculating it.


When $n$ is prime, the expression becomes $\mathcal{P}(n)+n^2-1$. The first few terms are 1
5
11
23
31
60
63
109
126
183
176
330
269
420
496
645
585
995
850. I didn't manage to find anything on OEIS.


Many thanks in advance.



$\sum_{1\leq a,b\leq n}\mathcal{P}(\gcd(a,b,n))$
Introducing $d:=\gcd(a,b,n)$, we get
$$\sum\_{1\leq a,b\leq n} \mathcal{P}(\gcd(a,b,n)) = \sum\_{d\mid n} \mathcal{P}(d) J\_2(\tfrac{n}d),$$
where $J\_2(\cdot)$ is the [Jordan totient function](https://en.wikipedia.org/wiki/Jordan%27s_totient_function) (see also [OEIS A007434](https://oeis.org/A007434)).


In particular, when $n$ is prime, we have the sum of just two terms:
$$\mathcal{P}(1) J\_2(n) + \mathcal{P}(n) J\_2(1) = n^2 - 1 + \mathcal{P}(n)$$
as expected.


