#include <stdio.h>
int gcd(int a, int b)
{
    int tmp;
    if (a < b) {
        tmp = a;
        a = b;
        b = tmp;
    }
    int r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main(void)
{
    int K;
    scanf("%d", &K);
    int S = 0;
    int x;
    int i,j,k;
    for (i = 1; i <= K; i++) {
        for (j = 1; j <= K; j++) {
            for (k = 1; k <= K; k++) {
                x = gcd(i,j);
                S += gcd(x,k);
            }
        }
    }

    printf("%d", S);

    return 0;
}