#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

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

int main(){
  ll k,sum=0,a,b;
  cin >> k;
  rep(i,1,k+1){
    rep(j,1,k+1){
      rep(l,1,k+1){
        a= gcd(i,gcd(j,l));
        sum+= a;
        //printf("%d,%d,%d:%d\n",i,j,l,a);
      }
    }
  }
  cout << sum << endl;
}
