#include <bits/stdc++.h>
#include<queue>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)

typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<string,string> Pstring;
typedef pair<double,double> Pdouble;



int main() {

  ll s;
  cin >> s;
  ll sum = 0;
  REP1(i,s){
    REP1(j,s){
      REP1(k,s){
        ll a = gcd(i,j);
        ll b = gcd(a,k);
        sum += b;
      }
    }
  }

  
  cout << sum << endl;
}