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

int gcd(int a, int b) {
  if(a < b) return gcd(b, a);
  int r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  int n;
  cin >> n;

  long long total = 0;
  for(int i=1; i <= n; i++) for(int j=1; j <= n; j++) for(int k=1; k <= n; k++) {
    total += gcd(i, gcd(j, k));
  }
  cout << total << endl;
}
