#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
static const int INF = 2000000000;

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

int main(){
  int k;
  cin >> k;
  ll ans = 0;
  for (int i = 1; i <= k; i++){
    for (int j = i; j <= k; j++){
      for (int l = j; l <= k; l++){
        ll tmp = gcd(i, gcd(j, l));
        int c = 0, d;
        if (i != j) c++;
        if (j != l) c++;
        if (l != i) c++;
        if (c == 0) d = 1;
        else if (c == 1 || c == 2) d = 3;
        else d = 6;
        ans += tmp * d;
      }
    }
  }
  cout << ans << endl;
}