#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
// Welcome to my source code!

int main() {
    int k;
    cin >> k;
    ll ans = 0;
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            for (int c = 1; c <= k; c++) {
                int t = __gcd(a, b);
                ans += __gcd(t, c);
            }
        }
    }
    cout << ans << endl;
}