#include <stdio.h>

int euclid(int a, int b)
{
    int temp;

    if (a < b) {
        temp = a;
        a = b;
        b = temp;
    }
    if (b < 1) {
        return -1;
    }

    if (a % b == 0) {
        return b;
    }
    return euclid(b, a % b);
}

int main(void) {
    int K;
    scanf("%d", &K);

    int result = 0;
    int num = 0;
    int i;
    int a, b, c;
    for (a = 1; a <=K; a++) {
        for (b = 1; b <= K; b++) {
            for (c = 1; c <= K; c++) {
                num = euclid(a, b);
                num = euclid(num, c);
                result += num;
            }
        }
    }
    printf("%d\n", result);
    return 0;
}