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

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;

int gcd_pair(int a, int b)
{
  int r;
  int 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 gcd(int *num, int c)
{
  int last_index;

  last_index = c - 1;
  if (last_index != 0)
  {
    for (int i = 0; i < last_index; i++)
    {
      if (num[i] != 0 && num[i + 1] != 0)
        num[i + 1] = gcd_pair(num[i], num[i + 1]);
      else
        break;
    }
  }
  return (num[last_index]);
}

int main(void) {
  int scan; // scanf result
  int answer; // to output 
  int k; // to input 
  int a;
  int b;
  int c;
  int *list;

  scan = scanf("%d", &k);
  answer = 0;
  list = (int *)malloc(sizeof(int) * 3);
  a = 1;
  while (a <= k) {
    b = 1;
    while (b <= k) {
      c = 1;
      while (c <= k) {
        list[0] = a;
        list[1] = b;
        list[2] = c;
        answer += gcd(list, 3);
        c++;
      }
      b++;
    }
    a++;
  }
  printf("%d", answer);
  return (0);
}
