#include <stdio.h>

int gcd(int a, int b) {
    int r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main() {
    long long x = 0;

    int K;
    scanf("%d", &K);

    for (int a = 1; a <= K; a++) {
        for (int b = 1; b <= a; b++) {
            for (int c = 1; c <= b; c++) {
                if (a == b && b == c) {
                    x += a;
                } else if (a == b || b == c || c == a){
                    x += 3 * gcd(gcd(a, b), c);
                } else {
                    x += 6 * gcd(gcd(a, b), c);
                }
            }
        }
    }

    printf("%lld\n", x);
    return 0;
}