#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll GCD(ll a, ll b) { return (b == 0)? a: GCD(b, a % b); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll N; cin >> N;
  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    for (ll j = 1; j <= N; j++) {
      for (ll k = 1; k <= N; k++) {
        ll g = GCD(i, j);
        g = GCD(g, k);
        ans += g;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}