#include <iostream>
#include <vector>
#include <cmath>
#include <map>
 
using namespace std;
typedef long long int ll;

int K;
int num[3];

int gcd3(int, int, int);

int main()
{
  int i,j,k;
  ll x;
  ll ans;
  ll md;
  ll sum = 0;
//  ans = 1000000000000000000LL;

  cin >> K;

  for (i=1; i<=K; i++) {
    for (j=1; j<=K; j++) {
      for (k=1; k<=K; k++) {
        sum += gcd3(i, j, k);
      }
    }
  }
  printf("%lld\n", sum);

  return 0;
}

#define MOD 1000000007LL

ll C(int, int);
int xgcd(int, int, int &, int &);
int gcd(int, int);
int modinv(int, int);
ll modInverse(ll, ll);
ll power(ll, ll, ll);

ll pow2(int);

int gcd3(int p, int q, int r) {
  int g1;

  g1 = gcd(p, q);
  return gcd(g1, r);
}

/*
  nCk�����߂�
  MOD(1000000007LL)�Ŋ������]�����Z�o
  */
ll C(int n, int k) {
  ll ret=1;
  int i;
  int a, b;

  a = k;
  b = n-k;
  if (a<b) swap(a,b);

  for (i=n; i>a; i--) {
    ret *= i;
    ret %= MOD;
  }
  for (i=2; i<=b; i++) {
    ret *= modinv(i, MOD);
    ret %= MOD;
  }
  return ret;
}


//�f������
vector<int> pr={2,3,5,7};

bool isprime(int n) {
  int i;
  int prime(int);
  int sz=pr.size();
  int sq = sqrt(n);
  for (i=1; i<sz; i++) {
    int p=pr[i];
    if (p>sq) return true;
    if (n%p==0) return false;
  }
  for (;;i++) {
    int p=prime(i);
    if (p>sq) return true;
    if (n%p==0) return false;
  }
}

//�f������
int prime(int n) {
  int last = pr.size();
  if (n<last) return pr[n];

  for (int p=pr.back()+2; last <= n; p+=2) {
    if (isprime(p)) {
      last++;
      pr.push_back(p);
    }
  }
  return pr.back();
}


//�f��������
//�����̐������f�������������B
//map�N���X�̃L�[�Ɋ�A�Ή������l�Ɏw���������Ă���
map<int, int> lc;
map<int, int> fact(int n) {
  int p;
  map<int, int> ret;
  int base, ix;

  int i;
  for (i=0; n>1; i++) {
    base = prime(i);
    ix = 0;
    while (n%base == 0) {
      ix++;
      n /= base;
    }
    if (ix > 0) {
      ret[base] = ix;
      auto itr = lc.find(base);
      if (itr == lc.end()) {
        lc[base] = ix;
      } else {
        lc[base] = max(ix, lc[base]);
      }
    } else {
      if (base * base >= n) {
        ret[n] = 1;
        auto itr = lc.find(n);
        if (itr == lc.end()) {
          lc[n] = 1;
        } else {
          lc[n] = max(1, lc[n]);
        }
        break;
      }
    }
  }
  return ret;
}

// �ő�������
// �f�����������ꂽ�l�ł̍ő����񐔎Z�o
map<int, int> lcm(map<int, int> m, map<int, int> n) {
  map<int, int> ret;

  for (auto itm=m.begin(); itm!=m.end(); itm++) {
    auto itn = n.find(itm->first);
    if (itn == n.end()) {
      ret[itm->first] = itm->second;
    } else {
      ret[itm->first] = max(itm->second, itn->second);
      n.erase(itm->first);
    }
  }
  for (auto itn=n.begin(); itn!=n.end(); itn++) {
    ret[itn->first] = itn->second;
  }

  return ret;
}

//���Z
// �f�����������ꂽ�l�̏��Z
map<int, int> vdiv(map<int,int> m, map<int, int> n) {
  map<int, int> ret;

  for (auto itm=m.begin(); itm!=m.end(); itm++) {
    auto itn = n.find(itm->first);
    if (itn == n.end()) {
      ret[itm->first] = itm->second;
    } else {
      ret[itm->first] = itm->second - itn->second;
      n.erase(itm->first);
    }
  }
  for (auto itn=n.begin(); itn!=n.end(); itn++) {
    ret[itn->first] = -itn->second;
  }
  return ret;
}
//mod�̏��]�Ƃ��āA�f���������������̂�int�^�ɕϊ�����
int toInt(map<int, int> f, int m) {
  ll lret=1;

  for (auto itr=f.begin(); itr != f.end(); itr++) {
    for (int j=0; j<itr->second; j++) {
      lret *= itr->first;
      lret %= m;
    }
  }
  return lret;
}

//�ő������� ���[�N���b�h�ݏ��@
int gcd(int m, int n) {
  if (m<n) swap(m, n);
  while (m%n) {
    m%=n;
    swap(m, n);
  }
  return n;
}
//�ő������� �g�����[�N���b�h�ݏ��@
int xgcd(int a, int b, int &x0, int &y0) {
  x0=1, y0=0;
  int x1=0, y1=1;
  int q;
  int at, x0t, y0t;
  while (b != 0) {
    q = a/b;
    at = b;
    b = a%b;
    a = at;
    x0t = x1;
    x1 = x0-q*x1;
    x0 = x0t;
    y0t = y1;
    y1 = y0-q*y1;
    y0 = y0t;
  }
  return a;
}
ll xgcd(ll a, ll b, ll &x0, ll &y0) {
  x0=1, y0=0;
  ll x1=0, y1=1;
  ll q;
  ll at, x0t, y0t;
  while (b != 0) {
    q = a/b;
    at = b;
    b = a%b;
    a = at;
    x0t = x1;
    x1 = x0-q*x1;
    x0 = x0t;
    y0t = y1;
    y1 = y0-q*y1;
    y0 = y0t;
  }
  return a;
}
//���W�����[�t��
//((ab mod n)(b^-1 mod n)) mod n = a mod n �ƂȂ� a�����߂��̂Ɏg��
//ab mod n �� b mod n���킩���Ă����Ƃ��� a mod n ���Z�o���邽��
//modInverse�͎��т���modinv�͕s��
int modinv(int a, int m) {
  int g, x, y;
  g = xgcd(a, m, x, y);
  if (g != 1) return -1;
  x %= m;
  if (x<0) x+=m;
  return x;
}
ll modinv(ll a, ll m) {
  ll g, x, y;
  g = xgcd(a, m, x, y);
  if (g != 1) return -1;
  x %= m;
  if (x<0) x+=m;
  return x;
}
ll power(ll x, ll y, ll p) {
  ll res = 1;
  x=x%p;
  while (y>0) {
    if (y&1) res = (res*x)%p;
    y = y>>1;
    x = (x*x) %p;
  }
  return res;
}
ll modInverse(ll a, ll m) {
  ll ans = power(a, m-2, m);
  return ans;
}

ll pow2(int n) {
  ll ret=1;
  ll r2=2;
  int i;

  for (i=n; i>0; i/=2) {
    if (i%2) ret *= r2;
    ret %= MOD;
    r2 *= r2;
    r2 %= MOD;

  }
  return ret;
}




Measured memory_bytes: 3788