#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;

int main() {
  ll k;
  cin >> k;
  vector<ll> t;
  FOR(i, 1, k + 1) FOR(j, 1, k + 1) { t.push_back(__gcd(i, j)); }

  ll ans = 0;
  for (auto x : t) {
    FOR(i, 1, k + 1) { ans += __gcd(x, ll(i)); }
  }
  cout << ans << endl;
  return 0;
}