/*
Author: Qaseem Hasan alias Mikepayne14(Codeforces,SPOJ) 
                           qaseem_hasan_ (Codechef,HackerRank,HackerEarth)
*/
 
 
//---------------------------------------------------------
//#pragma GCC optimize "trapv"
 
#include <bits/stdc++.h>
using namespace std;
//---------------------------------------------------------
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef double db;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<pair<int,int>>> vvpii;
typedef set<int> seti;
typedef priority_queue <int, vector<int>, greater<int>> rev_priority_queue;
 
const int INF = (int)1e9;
const int EPS = 1e-8;
const ll MOD  = 1000000007;
const ld PI = 3.14159265359;
 
#define acc accumulate
#define eb emplace_back
#define mii map <int,int>
#define F first
#define S second
#define MP make_pair
#define mid(s,e) (s+(e-s)/2)
#define fil(v,x) fill(all(v),x)
#define filcon(v,x) iota(all(v),x)
#define repi(n) for(int i=0;i<n;++i)
#define repj(n) for(int j=0;j<n;++j)
#define repr(n) for(int i=n-1;i>=0;--i)
//#define erase(v,e) v.erase(std::remove(v.begin(), v.end(), e), v.end())
#define sqr(x) ((x)*(x))
#define MEM(a,b) memset(a, b, sizeof(a))
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define inrange(i,a,b) ((i>=min(a,b)) && (i<=max(a,b)))
#define FLSH fflush(stdout)
// #define min_all(a,b,c,d,...) min({a,b,c,d,...})
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define make_unique(v) sort(all(v)); v.erase(unique(all(v)), v.end());
#define readfull(s) getline(cin,s)
#define printv(v) for(auto i:v) cout << i << " "
#define trace(x) cout<<#x<<" = { "<<x<<" }\n";
#define khatam '\n'
#define test int t; cin >> t; repi(t) {solve(); cout << khatam;}

//--------------------------------------------------------
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; } //x=min,y=item
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

template<typename T>
T fast_power(T a,T x)
{
    if(x==0)
        return 1;
    else if(x==1)
        return a;
    else
    {
        T R = fast_power(a,x>>1);
        if(x%2 == 0)
            return R*R;
        else
            return R*a*R;
    }
}

template<typename ForwardIterator,typename T>
T first_val(ForwardIterator first,ForwardIterator last,T value)
{
    auto it = std::lower_bound(first,last,value);
    return (it!=last)?(it - first) : -1;
}
 
template<typename ForwardIterator,typename T>
T last_val(ForwardIterator first,ForwardIterator last,T value)
{
    auto it = std::upper_bound(first,last,value);
    return (it!=last)?((it - first)) : -1;
}

template <typename T> T Dis(T x1,T y1,T x2, T y2)
{return sqrt(sqr(x1-x2) + sqr(y1-y2));}

template <typename T> T Angle(T x1,T y1,T x2, T y2)
{return atan((double)(y1-y2) / (double)(x1-x2));}

int Set(int N,int pos){ return N=N | (1<<pos);}
int Reset(int N,int pos){return N= N & ~(1<<pos);}
bool Check(int N,int pos){return (bool)(N & (1<<pos));}
template< class T, class X > inline T togglebit(T a, X i) { T t=1;return (a^(t<<i));}

//--------------------------------------------------------

//int ar[40001][40001];
 
//ll ar[10001];


/*bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.S > j.S;
}*/

//const int MAX_N = 15


void solve()
{
    int n;
    cin >> n;
    int f;
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            f = __gcd(i,j);
            for(int k=1;k<=n;k++)
            {
                sum += __gcd(f,k);
            }
        }
    }
    cout << sum << khatam;
}
int main()
{
    FAST_IO;
    /*#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif*/
//-------------------------------------------------------

    /*int n;
    cin >> n;
    ull sum =0 ;
    for(int i=1;i<=n;i++)
    {
        if(i%3 !=0 && i%5!=0)
            sum += i;
    }
    cout << sum << khatam;*/

        solve();
}

Measured memory_bytes: 3640