#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
  int k;
  cin >> k;
  ll ans = 0;
  for (int a = 1; a <= k; a++)
  {
    for (int b = 1; b <= k;b++){
      for (int c = 1; c <= k;c++){
        ans += __gcd(a, __gcd(b, c));
      }
    }
  }
  cout << ans << endl;
}