#include <stdio.h>
int func(int a, int b)
{
  int tmp;
  int 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()
{
  int n;
  scanf("%d",&n);
  int i,k,j = 1;
  int sum = 0;
  while (i <= n)
  {
    k = 1;
    while (k <= n)
    {
      j = 1;
      while (j <= n)
      {
        sum += func(func(i,j),k);
        j++;
      }
      k++;
    }
    i++;
  }
  printf("%d",sum);
}