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

int gcd(int a, int b, int c) {
  if (a == 1 || b == 1 || c == 1) return 1;
  else {
    int tmp = min(a, min(b, c));
    int gcd = 1;
    for (int i = tmp; i > 0; i--) {
      if (a%i == 0 && b%i == 0 && c%i == 0) {
        gcd = i;
        break;
      }
    }
    return gcd;
  }
}

int main() {
  int K;
  cin >> K;
  int res = 0;
  for (int i = 1; i <= K; i++) {
    for (int j = 1; j <= K; j++) {
      for (int k = 1; k <= K; k++) {
        res += gcd(i, j, k);
      }
    }
  }
  cout << res << endl;
}
