#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define ll long long

int gcd(int a, int b)
{
  return b ? gcd(b, a % b) : a;
}

int tgcd(int a, int b, int c)
{
  return gcd(gcd(a, b), c);
}

int main(void)
{
  int n, i, j, k;
  ll max = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++)
  {
    for (j = 1; j <= n; j++)
    {
      for (k = 1; k <= n; k++)
      {
        max += tgcd(i, j, k);
      }
    }
  }
  printf("%lld\n", max);
  return 0;
}