#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;
#define rep(i, N) for (ll i = 0; i < (N); i++)
typedef long long ll;

int gcd2(int a, int b)
{
    if (a % b == 0)
    {
        return b;
    }
    else
    {
        return gcd2(b, a % b);
    }
}
int gcd3(int a, int b, int c)
{
    a = gcd2(a, b);
    return gcd2(a, c);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k;
    cin >> k;
    ll sum = 0;
    for (int i = 1; i <= k; i++)
    {
        for (int l = 1; l <= k; l++)
        {
            for (int g = 1; g <= k; g++)
            {
                sum += gcd3(i, l, g);
            }
        }
    }
    cout << sum << endl;
}