#include<bits/stdc++.h>
using namespace std;

#define ll int long long
#define dll double long long
#define forei(i,n,x) for(int i=n;i<=x;i++)
#define fored(i,n,x) for(int i=n;i>=x;i--)
#define forni(i,n,x) for(int i=n;i<x;i++)
#define fornd(i,n,x) for(int i=n;i>x;i--)
#define SQ(a) (a)*(a)
#define MOD 1000000007
#define sortvi(v) sort(v.begin(),v.end())
#define sortvd(v) sort(v.rbegin(),v.rend())
#define pb push_back
#define pob pop_back
#define mp make_pair
#define pv(v) for(auto it: v) cout<<it
#define endl '\n'   //Take care in case of interactive problems
#define MAX1 100005
#define MAX2 200005
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<ll,ll> pl;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
ll gcd(ll a , ll b)
{
   if(b==0) return a;
   a%=b;
   return gcd(b,a);
}

ll gcda(ll i, ll j ,ll k)
{
    ll temp;
    temp=gcd(i,j);
    temp=gcd(temp,k);
    return temp;
}

int main() 
{ 
   ll k;cin>>k;
   ll sum=0;
   forni(i,1,k+1)
   {
       forni(j,1,k+1)
       {
           forni(l , 1 ,k+1)
           {
               sum+=gcda(i,j,l);
           }
       }
   }
   cout<<sum<<endl;
   
   
    return 0; 
} 