#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

ll gcd(ll a, ll b){
  if (a%b == 0)return(b);
  else return(gcd(b, a%b));
}

ll lcm(ll a, ll b){
   return a * b / gcd(a, b);
}

int main(){

  ll k;cin>>k;
  ll g[k+5][k+5];
  CLR(g,0);
  rep(i,1,k+1){
    rep(j,1,k+1){
      if(g[i][j]==0){
        g[i][j]=gcd(i,j);
        g[j][i]=gcd(i,j);
      }
    }
  }
  ll ans=0;
  rep(i,1,k+1){
    rep(j,1,k+1){
      rep(l,1,k+1){
        ans+=g[g[i][j]][l];
      }
    }
  }
  out(ans);


  return 0;
}
