TITLE: Number of pairs of nontrivial relatively prime divisors
QUESTION [5 upvotes]: Given a number, $n=p_1^{a_1}p_2^{a_2}\ldots p_k^{a_k}$, how many pairs of divisors (excluding 1) that are relatively prime are there?
For example: $n=2^2\cdot 3=12$. There are 6 distinct factors:$\{1,2,3,4,6,12\}$, and the only pairs of factors that are relatively prime to each other (excluding 1 of course) are $\{2,3\}$ and $\{2^2,3$}.
There was a similar question posted some years ago: Number of Relatively Prime Factors.
My thoughts are that it is the $\frac{P-1}{2}$ mentioned before, but removing the $(\tau(n)-1)$ pairs with 1 in them (where $\tau$ is the number of divisors function), making for a total of $\frac{P-1}{2}-\tau(n)+1$.

REPLY [2 votes]: At first let me change the question a bit, we will modify it to your original question at the end.
In counting such pairs we will make difference between the pairs $(a,b)$ and $(b,a)$; i.e. we will count $(a,b)$ and $(b,a)$ as 2 different pairs, (except for the case $(a,b)=(1,1)$).  
Also let $1$ to be a legal choice for the value of $a$ or $b$. For example when $n=12$ we have the following pairs:
(2,3), (3,2),
(4,3), (4,3),
(1,12), (1,6), (1,4), (1,3), (1,2), (1,1),
(12,1), (6,1), (4,1), (3,1), (2,1).


Let $n=p_1^{\alpha_1}p_2^{\alpha_2}...p_k^{\alpha_k}$ as you let, and let $(a,b)$ to be satisfied in the above conditions, and
let $a=p_1^{\gamma_1}p_2^{\gamma_2}...p_k^{\gamma_k}$ and $b=p_1^{\beta_1}p_2^{\beta_2}...p_k^{\beta_k}$. Fix a prime number which divides $n$, for example $p_i$.


Three cases may occure:

$p_i\nmid a$ and $p_i\nmid b$:

in this case we have $\beta_i=\gamma_i=0$, so in this case we have only one choice for the pair $(\beta_i,\gamma_i)$. 

$p_i\mid a$ and $p_i\nmid b$:

in this case we have $\gamma_i=0$,  $1\leq \beta_i \leq \alpha_i$; so in this case we have $\alpha_i$ choices for the pair $(\beta_i,\gamma_i)$.

$p_i\nmid a$ and $p_i\mid b$:

in this case we have $\beta_i=0$,  $1\leq \gamma_i \leq \alpha_i$; so in this case we have $\alpha_i$ choices for the pair $(\beta_i,\gamma_i)$.

$p_i\mid a$ and $p_i\mid b$: this case is impossible.

So in all we have $2\alpha_i+1$ choices for choosing $\beta_i$ and $\gamma_i$.


So we have $\prod_{i=1}^{k}(2\alpha_i+1)$ relatively prime pairs in the changed problem, but notice that in the original problem the pairs $(1,d)$ and $(d,1)$ are not legal. The number of illegal pairs of the form $(1,d)$ is equal to $\prod_{i=1}^{k}(\alpha_i+1)$; similarly the number of another illegal pairs is equal to $\prod_{i=1}^{k}(\alpha_i+1)$. But these pairs have a common pairs $(a,b)=(1,1)$, so number of the illegal pairs are equal to $2\Bigg(\prod_{i=1}^{k}(\alpha_i+1)\Bigg)-1$. 
So we have $\prod_{i=1}^{k}(2\alpha_i+1)-2\Bigg(\prod_{i=1}^{k}(\alpha_i+1)\Bigg)+1$ legal pairs. But remember that we count $(a,b)$ and $(b,a)$ as 2 different pairs, so we must divide the last formula by 2.

So the answer to your original problem is equal to:
$1/2\Bigg(\prod_{i=1}^{k}(2\alpha_i+1)+1\Bigg)-\Bigg(\prod_{i=1}^{k}(\alpha_i+1)\Bigg)$.
Notice that the second term is equal to the number of divisors of $n$
and the first term is equal to the number of divisors of $n^2$ plus one, divided by 2.
So the formula changes to 
$1/2\Bigg(d(n^2)+1\Bigg)-d(n)$, where $d(m)$ stands for the number of divisors of $m$.