#include <stdio.h>

long long int euclid(const long long int x, const long long int y) 
{
  long long int r;
  long long int temp_x = x, temp_y = y;

  while (!((r = temp_x % temp_y) == 0)) {
    temp_x = temp_y;
    temp_y = r;
  }

  return temp_y;
}

int main(void)
{
  long long int k;
  long long int a, b, c;
  long long int sum = 0, sum_temp = 0, sum_temp2 = 0, sum_temp3 = 0;
  long long int i;
  long long int gcd_bc, gcd;

  scanf("%lld", &k);

  /*a==b==c*/
  for (i = 1; i <= k; i++)
    sum += i;

  /*a > b > c*/
  for (a = 1; a <= k; a++) {
    for (b = 1; b < a; b++) {
      for (c = 1; c < b; c++) {
	gcd_bc = euclid(b, c);
	gcd = euclid(a, gcd_bc);
	sum_temp += gcd;
      }
    }
  }
  sum += (6 * sum_temp);

  /*a = b > c*/
  for (a = 1; a <= k; a++) {
    for (c = 1; c < a; c++) {
      gcd = gcd_bc = euclid(a, c);
      sum_temp2 += gcd;
    }
  }
  sum += (3 * sum_temp2);

  /*a > b = c*/
  for (a = 1; a <= k; a++) {
    for (b = 1; b < a; b++) {
      gcd = gcd_bc = euclid(a, b);
      sum_temp3 += gcd;
    }
  }
  sum += (3 * sum_temp3);

  /*sum*/
  printf("%lld", sum);

  return 0;
}
