#include<iostream>
using namespace std;
#define ll long long

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

int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll k;
  cin >> k;
  
 	ll g1, g2, sum=0;
  for(ll i=1; i<=k; i++){
    for(ll j=1; j<=k; j++){
      g1 = GCD(i,j);
      for(ll m=1; m<=k; m++){
        g2 = GCD(g1, m);
        sum += g2;
      }
    }
  }
  cout << sum;
  
    return 0;
}