#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int gcd(int a, int b)
{
  int tmp,r;
  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(void)
{
  int K,sum;
  int i,j,k;
  sum = 0;

  scanf("%d",&K);

  for(i=1;i<=K;i++)
  {
    for(j=1;j<=K;j++)
    {
      for(k=1;k<=K;k++)
      {
        sum += gcd(gcd(i,j),k);
      }
    }
  }

  printf("%d\n",sum);

  return 0;
}