#include <bits/stdc++.h>
using namespace std;
int64_t getgcd(int64_t n, int64_t m)
{
  int64_t r;
  if (n > m)
  {
    int64_t t = m;
    m = n;
    n = t;
  }
  while ((r = m % n) != 0)
  {
    m = n;
    n = r;
  }
  return n;
}
int main()
{
  int64_t k;
  cin >> k;
  int64_t gcd;
  int64_t ans;
  vector<int64_t> z(1);
  vector<int64_t> vecA(k);
  vector<int64_t> vecB(k);
  vector<int64_t> vecC(k);
  for (int i = 0; i < k; i++)
  {
    vecA.at(i) = i + 1;
    vecB.at(i) = i + 1;
    vecC.at(i) = i + 1;
  }

  for (int64_t i = 0; i < k; i++)
  {
    for (int64_t j = 0; j < k; j++)
    {
      for (int64_t l = 0; l < k; l++)
      {
        gcd = getgcd(getgcd(vecA.at(i), vecB.at(j)), vecC.at(l));
        ans += gcd;
      }
    }
    z.at(0) = ans;
  }
  cout << z.at(0) << endl;
}