TITLE: $\sum_{1\leq a,b\leq n}\mathcal{P}(\gcd(a,b,n))$
QUESTION [6 upvotes]: 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.

REPLY [5 votes]: 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 (see also OEIS 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.