I have the following summation:
$$F(k)=\sum\limits_{n=1}^k\sum\limits_{d|n}\gcd\left({d},{\frac{n}{d}}\right)$$
This is nearly impossible to compute (using coding) for large numbers, due to the time it'd take.
It's been suggested that the above summation can be simplified to this:
$$F(k)=\sum_{d=1}^{d^2\leqslant k}\ \sum_{n=1}^{nd\leqslant k}\gcd({d},{n})$$
I've tried testing the simplification, and it doesn't work. For instance, F(10) gives an output of 22 instead of 32.
How do I simplify the first summation?
Stuff here might be relevant, but I'm not sure: Wikipedia: Divisor function.
EDIT: Algorithm for thefunkyjunky's suggestion:
long k = 10;
for (long d = 1; d*d <= k; d++) {
for(long n = 1; n*d <= k; n++) {
if (d*d <= n) result = result.add(BigInteger.valueOf(GCD(d,n)));
}
}

You can use the fact that if d is a divisor such that $d<\sqrt{n}$, then $\frac{n}{d} > \sqrt{n}$ and $\frac{n}{d}$ is also a divisor of $n$. So $gcd(d, \frac{n}{d})$ form pairs of gcds, which means that you can compute for divisors only smaller than $\sqrt{n}$ and then multiply the sum by $2$ which is(I think) fast enough.
EDIT: I forgot to add that you need to make a special case when $n$ is a square, because then you have $d$ that $d^2=n$ and the $gcd(d, d)$ factor must be counted only once, not twice.
EDIT2: The algorithm I had in mind was:
But I think yours is faster. What you do(if you haven't understood it) in your algorithm is just finding all pairs $(x, y)$ such that $xy \leq k$ which means that their gcd is included in the sum as divisors of some $n = xy$
EDIT3: The algorithm that you firstly tried to implement(the rewritten sum) has a mistake. It can be written as(The following is a combination of my and your solution):
Please comment to tell me whether it passes(I'm also interested)!