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

int gcd(int a, int b) {
  int v0 = a, v1 = b, v2 = a % b;
  while (v2 != 0) {
    v0 = v1;
    v1 = v2;
    v2 = v0 % v2;
  };
  return v1;
}

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