#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define in insert
#define b_s binary_search
#define rev reverse
#define all(x) (x).begin(),(x).end()
#define pf push_front
#define pob pop_back
#define pof pop_front
#define u_b upper_bound
#define l_b lower_bound
#define ios ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define mod 998244353
#define Max 100005

using namespace std;

int main()
{
    int k;
    cin >> k;
    ll ans = 0, g, temp;
    for(int i = 1; i <= k; i++)
    {
        for(int j = 1; j <= k; j++)
        {
            g = __gcd((ll)i, (ll)j);
            temp = g;
            for(int s = 1; s <= k; s++)
            {
                g = __gcd(g, (ll)s);
                ans += g;
                g = temp;
            }
        }
    }
    cout << ans << endl;
}
