#include <bits/stdc++.h>
using namespace std;

long long gcd(long long a,long long b){
  long long r,tmp;

  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main(){
  int n;
  cin >> n;

  long long sum=0;
  for (int i = 1; i <= n; i++)
  {
    for (int j = 1; j <= n; j++)
    {
      long long gcdij=gcd(i,j);
      for (int k = 1; k <= n; k++)
      {
        sum+=gcd(gcdij,k);
      }
    }
  }
  cout << sum << endl;
}