#include <bits/stdc++.h>

using ll = long long;
using ull = unsigned long long;

using namespace std;

ll findGCD(ll x, ll y, ll z)
{
    ll result = __gcd(x, y);
    result = __gcd(result, z);
    return result;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll N, sum = 0;
    cin>>N;

    for(ll i=1;i<=N;++i)
    {
        for(ll j=1;j<=N;++j)
        {
            for(ll k=1;k<=N;++k)
                sum += findGCD(i,j,k);
        }
    }

    cout<<sum<<'\n';

    return 0;
}