#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define N 1000001
int phi[N];
ll a[N];
#define GC getchar_unlocked()
int scan() {
int ret = 0;
int ip = GC;
for (; ip < '0' || ip > '9'; ip = GC)
;
for (; ip >= '0' && ip <= '9'; ip = GC)
ret = ret * 10 + ip - '0';
return ret;
}
int main() {
int i, j, n;
for (i = 1; i < N; i++)
phi[i] = i;
phi[1] = 0;
for (i = 2; i < N; i++)
if (phi[i] == i)
for (j = i; j < N; j += i)
phi[j] -= phi[j] / i;
for (i = 1; i < N; i++) {
for (j = i; j < N; j += i) {
a[j] += (i * phi[(j / i)]);
}
}
for (i = 2; i < N; i++)
a[i] += a[i - 1];
while (1) {
n = scan();
assert(n < N);
if (n == 0)
break;
printf("%lld\n", a[n]);
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNkZWZpbmUgTiAxMDAwMDAxCmludCBwaGlbTl07CmxsIGFbTl07CiNkZWZpbmUgR0MgZ2V0Y2hhcl91bmxvY2tlZCgpCmludCBzY2FuKCkgewogIGludCByZXQgPSAwOwogIGludCBpcCA9IEdDOwogIGZvciAoOyBpcCA8ICcwJyB8fCBpcCA+ICc5JzsgaXAgPSBHQykKICAgIDsKICBmb3IgKDsgaXAgPj0gJzAnICYmIGlwIDw9ICc5JzsgaXAgPSBHQykKICAgIHJldCA9IHJldCAqIDEwICsgaXAgLSAnMCc7CiAgcmV0dXJuIHJldDsKfQoKaW50IG1haW4oKSB7CiAgaW50IGksIGosIG47CiAgZm9yIChpID0gMTsgaSA8IE47IGkrKykKICAgIHBoaVtpXSA9IGk7CiAgcGhpWzFdID0gMDsKICBmb3IgKGkgPSAyOyBpIDwgTjsgaSsrKQogICAgaWYgKHBoaVtpXSA9PSBpKQogICAgICBmb3IgKGogPSBpOyBqIDwgTjsgaiArPSBpKQogICAgICAgIHBoaVtqXSAtPSBwaGlbal0gLyBpOwogIGZvciAoaSA9IDE7IGkgPCBOOyBpKyspIHsKICAgIGZvciAoaiA9IGk7IGogPCBOOyBqICs9IGkpIHsKICAgICAgYVtqXSArPSAoaSAqIHBoaVsoaiAvIGkpXSk7CiAgICB9CiAgfQogIGZvciAoaSA9IDI7IGkgPCBOOyBpKyspCiAgICBhW2ldICs9IGFbaSAtIDFdOwogIHdoaWxlICgxKSB7CiAgICBuID0gc2NhbigpOwogICAgYXNzZXJ0KG4gPCBOKTsKICAgIGlmIChuID09IDApCiAgICAgIGJyZWFrOwogICAgcHJpbnRmKCIlbGxkXG4iLCBhW25dKTsKICB9CiAgcmV0dXJuIDA7Cn0=