#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const ll INF = 1LL << 60;

 int main() {
   ll K, ans = 0;

   cin >> K;

   vector<vector<ll>> memo(K + 1, vector<ll>(K + 1));
   vector<ll> ab;

   for (ll i = 1; i <= K; i++) {
     for (ll j = 1; j <= K; j++) {
       memo.at(i).at(j) = __gcd(i, j);
       ab.emplace_back(__gcd(i, j));
     }
   }

   for (ll v : ab) {
     for (ll i = 1; i <= K; i++) {
       ans += __gcd(v, i);
     }
   }

   cout << ans << endl;
 }
