#include <stdio.h>
#include <stdlib.h>

int GCD(int a, int b) {
    int r, tmp;
    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 main() {
    int K, a, b, c, ans = 0;
    scanf("%d", &K);

    for (a = 1; a <= K; a++) {
        for (b = 1; b <= K; b++) {
            for (c = 1; c <= K; c++) {
                ans = ans + GCD(GCD(a, b), c);
            }
        }
    }

    printf("%d\n", ans);
    return 0;
}
