#include <bits/stdc++.h>
using namespace std;

int gcd(int a, int b) {
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main() {
  int K, p, q, r;
  long result = 0;
  cin >> K;
  for (p = 1; p <= K; p++) {
    for (q = 1; q <= K; q++) {
      for (r = 1; r <= K; r++) {
        // cout << result << endl;
        result += gcd(p, gcd(q, r));
      }
    }
  }
  cout << result << endl;
}