#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int inf = 1000000000; 

ll GCD (ll x, ll y){
  ll a = max(x,y);
  ll b = min(x,y);
  if(a%b == 0) return b;
  return GCD(b,a%b);
}

int main(){
    int k;
    ll ans = 0;
    rep(i,k){
        rep(j,k){
            rep(l,k){
                ans += GCD(GCD(i,j),l);
            }
        }
    }
    cout << ans << endl;
}