    #include <bits/stdc++.h>
    using namespace std;
    #define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
    #define REP(i, n) FOR(i, 0, n)
    #define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
    #define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
    #define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
    #define fi first
    #define se second
    #define ll long long
    #define int long long
    #define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
     
    #define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
    #define dv(name, value) cerr << (name) << " is " << (value) << endl
    #define da(itr, v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl
     
    int gcd(int vEd, int vIng) {
      if (vEd % vIng == 0) {
        return vIng;
      }
     
      gcd(vIng, vEd % vIng);
    }
     
    signed main(){
      int K; cin >> K;
      int sum = 0;
     
      FOR(x, 1, K+1){
        FOR(y, 1, K+1){
          FOR(z, 1, K+1){
            sum += gcd(gcd(x, y), z);
          }
        }
      }
     
      cout << sum << endl;
    }