#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
int32_t main() {
    fast_io();
    int k;
    cin >> k;
    int res = 0;
    for (int i = 1; i <= k; i++)
    {
        for (int j = 1; j <= k; j++)
        {
            for (int l = 1; l <= k; l++)
            {
                int v = __gcd(i, j);
                v = __gcd(v, l);
                res += v;
            }
        }
    }
    cout << res << "\n";
    return 0;
}