#include <stdio.h>
int gcd(int a, int b)
{
  int r;
  if (a > b) {
    int t = b;
    b = a;
    a = t;
  }
  
  while ((r = b % a) != 0) {
    b = a;
    a = r;
  }
  
  return a;
}

int main(void)
{
  int k;
  int wa = 0;
  int l, m, n;
  
  scanf("%d",&k);
  
  for (l=1; l<=k; l++) {
    for (m=1; m<=k; m++) {
      for (n=1; n<=k; n++) {
        wa += gcd(gcd(l,m),n);
      }
    }
  }
  
  printf("%d",wa);
  
  return 0;
}