#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
ll N;
int main(){
    cin>>N;
    ll ans=0;
    for(ll i=1;i<=N;i++){
        for(ll j=1;j<=N;j++){
            for(ll k=1;k<=N;k++){
                ans+=gcd(gcd(i,j),k);
            }
        }
    }
    cout<<ans;
    return 0;
}