#include <iostream>
#include <algorithm>
#define rep(i, n) for (int i = 1; i <= n; i++)
using namespace std;
using ll = long long;
using p = pair<int, int>;

int gcd(int a, int b) {
  int ret=1;
  int max = a < b ? b : a;
  for (int i = 1; i <= max; i++) {
    if (a%i==0 && b%i==0)
      ret = i;
  }
  return ret;
}
int gcd3(int a, int b, int c) {
  int ret = gcd(gcd(a, b), c);
  return ret;
}
int main() {
  int K, i, j, h, sum=0;
  cin >> K;
  rep(i, K) {
    rep(j, K) {
      rep(h, K) {
        sum += gcd3(i, j, h);
      }
    }
  }
  cout << sum << endl;
  return 0;
}
