#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(a%b,b);
}
int main() {
ll sum=0;
ll k;
cin >> k;
for (ll i = 1; i <= k; i++)
{
 for (ll j = 1; j <= k; j++)
  { 
    for (ll b = 1; b <= k; b++)
    {
      sum+=gcd(i,gcd(j,b));
    } 
  }
}

cout << sum <<endl;


}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/