#include <iostream>
#include <vector>
using namespace std;

using int64 = long long;

int gcd(int a, int b) {
  static vector<vector<int>> gcd_(201, vector<int>(201, 0));
  if (b == 0)
    return a;
  if (gcd_[a - 1][b - 1])
    return gcd_[a - 1][b - 1];
  
  return gcd_[a - 1][b - 1] = gcd(b, a % b);
}

int main() {
  int k;
  cin >> k;
  int64 sum = 0;
  for (int a = 1; a <= k; ++a) {
    for (int b = 1; b <= k; ++b) {
      for (int c = 1; c <= k; ++c) {
        sum += gcd(a, gcd(b, c));
      }
    }
  }
  cout << sum << "\n";

  return 0;
}
