TITLE: How to simplify $F(k)=\sum\limits_{n=1}^k\sum\limits_{d|n}\gcd({d},{\frac{n}{d}})$?
QUESTION [6 upvotes]: 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)));
        }
    }

REPLY [2 votes]: I have found another way to calculate this, although I am not really answering the question of how to rearrange the original sum.
I started by considering for myself the possible pairs and the $gcd$s:
n= 1:  (1,1)                        1                 f( 1)=1   F( 1)= 1
n= 2:  (1,2)  (2,1)                 1  1              f( 2)=2   F( 2)= 3 
n= 3:  (1,3)  (3,1)                 1  1              f( 3)=2   F( 3)= 5
n= 4:  (1,4)  (2,2)  (4,1)          1  2  1           f( 4)=4   F( 4)= 9
n= 5:  (1,5)  (5,1)                 1  1              f( 5)=2   F( 5)=11
n= 6:  (1,6)  (2,3)  (3,2)  (6,1)   1  1  1  1        f( 6)=4   F( 6)=15
n= 7:  (1,7)  (7,1)                 1  2  1           f( 7)=2   F( 7)=17
n= 8:  (1,8)  (2,4)  (4,2)  (8,1)   1  2  2 1         f( 8)=6   F( 8)=23
n= 9:  (1,3)  (3,3)  (9,1)          1  3  1           f( 9)=5   F( 9)=28
n=10: (1,10)  (2,5)  (5,2) (10,1)   1  1  1  1        f(10)=4   F(10)=32

I didn't find it obvious what was going on here, so I laid out the same results like this:

I noticed that the table can be viewed as a set of inverted "V"s.
The entries for $(1,n)$ and $(n,1)$ make one such V: with all the $gcd$ equal to 1.
The entries for $(2,\frac n2)$ and $(\frac n2,2)$ make another V (marked in green): but the entries start with 2 and then alternate 1, 2, 1, 2, ...
It is important to note also that the $i$th V begins at $n=i^2$ with a single value $gcd = i$, then continues on with $2(i-1)$ values of $gcd=1$ and then 2 values of $gcd=i$, with this pattern being repeated.
By my method we have $F(n)=\Sigma_{i=1}^{i={\sqrt n}}V(i,n)$
where $V(i,n)$ is the sum of the values in the $i$th V and is found by this algorithm:
Find positive integers $p$ and $q$ so that $n=pi^2+qi+r$.
Then $V(i,n)=i + 2(p-1)(2i-1)+2q$
I think this might be better because there is no need to calculate any $gcd$.