#include <stdio.h>

static unsigned long int gcd(unsigned int a, unsigned int b) {
    if (a > b) {
        unsigned int temp = a;
        a = b;
        b = temp;
    }

    if (a == 0) {
        return b;
    }

    b = b % a;
    return gcd(b, a);
}

int main(void) {
    unsigned int k;
    scanf("%u", &k);
    unsigned long int sum = 0;
    unsigned int a, b, c;
    for (a = 1; a <= k; a++) {
        for (b = 1; b <= k; b++) {
            for (c = 1; c <= k; c++) {
                sum += gcd(gcd(a, b), c);
            }
        }
    }

    printf("%lu\n", sum);
    return 0;
}