#include <stdio.h>

int gcd2(int x, int y)
{
    int temp;
    if (x > y)
    {
        temp = x;
        x = y;
        y = temp;
    }
    while (x != 0)
    {
        temp = y % x;
        y = x;
        x = temp;
    }
    return y;
}

int gcd3(int x, int y, int z)
{
    int temp1, temp2;
    temp1 = gcd2(x, y);
    temp2 = gcd2(y, z);
    return gcd2(temp1, temp2);
}

int main(void)
{
    int c, d, e, K, ans = 0;
    scanf("%d", &K);
    for (c = 1; c <= K; ++c)
    {
        ans += c;
        for (d = c + 1; d <= K; ++d)
        {
            ans += 6 * gcd2(c, d);
            for (e = d + 1; e <= K; ++e)
            {
                ans += 6 * gcd3(c, d, e);
            }
        }
    }
    printf("%d", ans);
    return 0;
}
