#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;

int g[205][205];

int main()
{
    int k;
    cin >> k;
    ll sol = 0;
    for (int a = 1; a <= k; ++a)
        for (int b = 1; b <= k; ++b)
            g[a][b] = gcd(a, b);
    for (int a = 1; a <= k; ++a)
        for (int b = 1; b <= k; ++b)
            for (int c = 1; c <= k; ++c)
                sol += g[a][g[b][c]];
    cout << sol;
}
