#include <iostream>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()

int gcd(ll a, ll b) {
  ll c;
  if (a > b) swap(a, b);
  while (b % a > 0) {
    c = b % a;
    b = a;
    a = c;
  }
  return a;
}
int main() {
  int k, ans = 0;
  cin >> k;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      for (int l = 1; l <= k; l++) {
        ans += gcd(gcd(i, j), l);
      }
    }
  }
  cout << ans << endl;
}