#include <stdio.h>

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

int main() {
    long K, a, b, c, d, res = 0;
  	scanf("%ld", &K);
    for (a = 1; a <= K; a++) {
        for (b = 1; b <= K; b++) {
            for (c = 1; c <= K; c++) {
                d = gcd(a, b);
                res += gcd(c, d);
            }
        }
    }
    printf("%.ld\n", res);
}