#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
    int K;
    ll sum = 0;

    scanf("%d", &K);
    for (int a = 1; a <= K; a++)
        for (int b = 1; b <= K; b++)
            for (int c = 1; c <= K; c++)
                sum += __gcd(__gcd(a, b), c);

    printf("%lld\n", sum);

    return 0;
}