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

int gcd(int x, int y) {
  return (x % y) ? gcd(y, x % y) : y;
}

signed main() {
  int N;
  cin >> N;
  int a = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      for (int k = 1; k <= N; k++) {
        int b = gcd(i, j);
        b = gcd(b, k);
        a += b;
      }
    }
  }
  cout << a << endl;
}