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

int main() {
  int k;
  cin >> k;
  int64_t sum = 0;

  for (int i = 1; i < k + 1; i++) {
    for (int j = 1; j < k + 1; j++) {
      for (int n = 1; n < k + 1; n++) {
        sum += gcd(i, (gcd(j, n)));
      }
    }
  }

  cout << sum << endl;

}

int gcd(int a, int b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
