#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000001;

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

int gcd_2(int a, int b, int c){
  return gcd(a, gcd(b, c));
}
    

int main(){
  int n;
  ll ans = 0;
  cin >> n;
  rep(i, n){
    rep(j, n){
      rep(k, n){
        ans = ans + gcd_2(i,j,k);
      }
    }
  }
  cout << ans <<endl;
}