#include <bits/stdc++.h>
using namespace std;
typedef long long int llint;
llint mod = 1000000007;

int gcd(int x, int y) {
  int M = max(x, y);
  int m = min(x, y);
  while (M%m!=0) {
    int p = M % m;
    M = m;
    m = p;
  }
  return m;
}

int main() {
  int n;
  cin >> n;
  int count = 0;
  for (int i = 1; i < n + 1; i++) {
    for (int j = i; j < n + 1; j++) {
      for (int k = j; k < n + 1; k++) {
        int g = gcd(i, gcd(j, k));
        if (i == j && j == k) {
          count += g;
        }
        else if (i != j && j != k && k != i) {
          count += 6 * g;
        }
        else {
          count += 3 * g;
        }
      }
    }
  }
  cout << count <<endl;
} 