#include <iostream>

using namespace std;

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

int main() {
    int K;
    long long int res = 0;
    cin >> K;

    for (int a = 1; a <= K; ++a) {
        for (int b = 1; b <= K; ++b) {
            for (int c = 1; c <= K; ++c) {
                res += gcd(gcd(a, b), c);
            }
        }
    }
    cout << res;
    return 0;
}