#include <stdio.h>
#include <stdlib.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;

int GCD(int a, int b)
{
    int r = a % b;
    while (r != 0)
    {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main(void)
{
    int k, p[200];
    int ans = 0, dig;
    scanf("%d", &k);

    for (int i = 1; i <= k; i++)
        for (int j = 1; j <= k; j++)
            for (int h = 1; h <= k; h++)
                ans += GCD(GCD(i, j), h);

    printf("%d\n", ans);
    return 0;
}