#include <stdio.h>

typedef long long int64;

int gc(int a, int b) 
{
    int tmp, r;
    if (a < b) {
        tmp = a;
        a = b;
        b = tmp;
    }
    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

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

int main()
{
    int k;
    scanf("%d", &k);
    int64 a = 0;

    for (int i = 1; i != k + 1; i++)
    {
        for (int j = 1; j != k + 1; j++)
        {
            for (int l = 1; l != k + 1; l++)
            {
                a += gcd(i, j, l);
            }
        }
    }

    printf("%lld", a);
    return 0;
}