How does the cardinality of $$\{(a,b): 1 \leq a,b \leq n, \ 2ab/(a+b) \ \mbox{is an integer}\}$$ grow as a function of $n$? What about $$\{(a,b): 1 \leq a,b \leq n, \ \sqrt{ab} \ \mbox{is an integer}\}?$$ For $n=10$, $100$, $1000$, and $10000$ the two functions of $n$ are close and getting closer (in relative terms); one might even surmise that the ratio tends to 1.


For those who care, those ratios are $18/14 = 1.2857$, $310/272 = 1.1397$, $4344/3976 = 1.0926$, and $57296/52756 = 1.0861$. Numerators are for the geometric mean and denominators are for the harmonic mean. On the other hand, $10000$ is not very big, so the data from the previous sentence may not reflect the true asymptotic behavior of the two functions.



Asymptotics for pairs of positive integers whose harmonic (resp. geometric) mean is an integer
[CORRECTED 8/28]


I think the asymptotic ratio is $(4/3)\*\ln(2)\approx 0.924196$.


$$G(n) = (6/\pi^2)\*n\*\ln(n) + O(n)$$
$$H(n) = (8\ln(2)/\pi^2)\*n\*\ln(n) + O(n)$$


The proof for the geometric mean goes as Noam Elkies posted.


For the harmonic mean, we will first characterize "primitive" solutions: pairs $(a,b)$ with $\gcd(a,b)=1$ and $(a+b)|(2ab)$.


Let $r=p/q$ be a rational number in lowest terms. Then $(a,a\*r)$ has integer harmonic mean iff $(p+q)|(2ap)$, which is true iff $a$ is a multiple of $(p+q)/\gcd(p+q,2)$. And we also need $a\*r$ to be an integer, which means $q|a$. So we get a primitive solution iff $a=q(p+q)/\gcd(p+q,2)$.


So the primitive solutions are:


$(p(p+q),q(p+q))$ when $\gcd(p,q)=1$ and $p+q$ is odd,


$(p(p+q)/2,q(p+q)/2)$ when $\gcd(p,q)=1$ and $p+q$ is even.


Or, equivalently,


$(p\*s, (s-p)\*s)$ when $\gcd(p,s)=1$, $s$ is odd, $p<s$,


$(p\*s/2, (s-p)\*s/2)$ when $gcd(p,s)=1$, $s$ is even, $p<s$.


We will count all solutions bounded by $n$ by assuming $s/2<p<s$ (except $(p,s)=(1,2)$), and then multiplying by 2 for symmetry:


$$n+2 \int\_{1}^{\sqrt{n}} \int\_{p}^{\min(2p,n/p)} \frac{1}{2}\frac{8}{\pi^2}\frac{n}{ps} \,ds\,dp
+ 2 \int\_{1}^{\sqrt{2n}} \int\_{p}^{\min(2p,2n/p)} \frac{1}{2}\frac{4}{\pi^2}\frac{n}{ps/2} \,ds\,dp $$
$$ = n + \int\_{1}^{\sqrt{n/2}} \int\_{p}^{2p} \frac{8}{\pi^2}\frac{n}{ps} \,ds\,dp
 + \int\_{\sqrt{n/2}}^{\sqrt{n}} \int\_{p}^{n/p} \frac{8}{\pi^2}\frac{n}{ps} \,ds\,dp \\ $$
$$ + \int\_{1}^{\sqrt{n}} \int\_{p}^{2p} \frac{8}{\pi^2}\frac{n}{ps} \,ds\,dp
 + \int\_{\sqrt{n}}^{\sqrt{2n}} \int\_{p}^{2n/p} \frac{8}{\pi^2}\frac{n}{ps} \,ds\,dp $$
$$ \asymp n + (4\ln(2)/\pi^2)\*n\*\ln(n)
 + (2\ln(2)^2/\pi^2)\*n $$
$$ + (4\ln(2)/\pi^2)\*n\*\ln(n)
 + (2\ln(2)^2/\pi^2)\*n$$
$$ = (8\ln(2)/\pi^2)\*n\*\ln(n) + O(n) $$


(Note: the exact integrals should have $\lfloor n/(ps)\rfloor$ in place of $n/(ps)$, but this is bounded above by $n/(ps)$ and bounded below by $n/(ps)-1$, and we can compute both integrals and show that they are asymptotically equivalent.)


