#include <stdio.h>
int max(int a, int b, int c)
{
  if (a >= b && a >= c) {
    return a;
  } else if (b >= a && b >= c) {
    return b;
  } else {
    return c;
  }
}

int gcd(int a, int b, int c, int g)
{
  int a_ = a%g;
  int b_ = b%g;
  int c_ = c%g;
  if (a/g*g - a == 0 && b/g*g - b == 0 && c/g*g - c == 0) {
    return g;
  } else {
    return gcd(a, b, c, max(a_, b_, c_));
  }
}

int main()
{
  long ans = 0;
  int K;
  scanf("%d", &K);
  for (int i = K; i > 0; --i) {
    for (int j = i; j > 0; --j) {
      for (int l = j; l > 0; --l) {
        int g = gcd(i, j, l, l);
        if (i == j && j == l) {
          ans += g;
        } else if (i == j || j == l) {
          ans += g*3;
        } else {
          ans += g*6;
        }
      }
    }
  }
  printf("%ld", ans);
}