#include <bits/stdc++.h>
using namespace std;
int main() {
    int K;
    cin >> K;
    int k[] = {K ,K ,K};

    long long tmp = 0;
    for (int a = 1; a <= K; a++) {
        for (int b = 1; b <= K; b++) {
            for (int c = 1; c <= K; c++) {
                tmp += __gcd(__gcd(a, b), c);
            }
        }
    }
    cout << tmp << endl;
    return 0;
}

