#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}
    

int main(){
  ll n; cin >> n; ll sum = 0;
  
  for(ll i=1; i <= n; i++){
    for(ll j=1; j <= n; j++){
      for(ll k=1; k <= n; k++){
        sum += gcd(gcd(i,j),k);
      }
    }
  }
  
  cout << sum << endl;
}
  