#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll gcd(ll a,ll b){
		if(a==0)return b;
		return gcd(b%a,a);
}
int main()
{
  ll n;
  cin >> n;
  ll s=0;
  for(ll a=1;a<=n;a++)
  {
      for(ll b=1;b<=n;b++)
      {
          for(ll c=1;c<=n;c++)
          {
              s=s+gcd(gcd(a,b),c);
          }
          
      }
  }
  cout <<s;
}