#include <bits/stdc++.h>

using namespace std;
int ok(int a, int b, int c)
{
    return (__gcd(a, __gcd(b, c)));
}
int main()
{
    int n;
    long long res = 0;
    cin >> n;
    for (int a = 1; a <= n; a++)
        for (int b = 1; b <= n; b++)
            for (int c = 1; c <= n; c++) res += ok(a, b, c);
    cout << res;
    return 0;
}
