#include <bits/stdc++.h>
#include <math.h>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

// 最大公約数
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}

int main()
{
    ll k;
    cin >> k;
    ll sum = 0;
    for (ll a = 1; a <= k; a++) {
        for (ll b = 1; b <= k; b++) {
            for (ll c = 1; c <= k; c++) {
                ll g = gcd(a, b);
                if (g == 1) {
                    sum += 1;
                } else {
                    g = gcd(g, c);
                    sum += g;
                }
            }
        }
    }
    cout << sum << endl;
}