#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
int main(){
  ll k; cin >> k;
  ll ans=0;
  rep(a,k){
    rep(b,k){
      rep(c,k){
        ans+=__gcd(__gcd(a,b),c);
      }
    }
  }
  cout << ans;
  return 0;
}
