#include <stdio.h>

int gcd(int x, int y)
{
    return (x % y) ? gcd(y, x % y) : y;
}

int gcd3(int a, int b, int c)
{
    return gcd(gcd(a, b), c);
}

int main()
{
    int k;
    int a, b, c;
    int sum = 0;

    scanf("%d", &k);

    for (a = 1; a <= k; a++) {
        for (b = 1; b <= k; b++) {
            for (c = 1; c <= k; c++) {
                sum += gcd3(a, b, c);
            }
        }
    }

    printf("%d\n", sum);

    return 0;
}