#include <bits/stdc++.h>
using namespace std;
int main() {
  int K;
  cin >> K;
  long Ans = 0;
  for (int i = 1; i <= K; i++) {
    for (int j = 1; j <= K; j++) {
      for (int k = 1; k <= K; k++) {
        Ans += gcd(i, gcd(j, k));
      }
    }
  }
  cout << Ans << endl;
  return 0;
}