#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>



int main() {
  unsigned long long a, b, c, r, tmp, i, j = 0, k, num = 0,  ans = 0, K = 0;
  scanf("%llu", &K);
  for (i = 1; i <= K; i++) {
    for (j = 1; j <= K; j++) {
      a = i;
      b = j;
      /* 自然数 a > b を確認・入替 */
      if (a < b) {
        tmp = a;
        a = b;
        b = tmp;
      }

      /* ユークリッドの互除法 */
      r = a % b;
      while (r != 0) {
        a = b;
        b = r;
        r = a % b;
      }
      num = b;
      for (k = 1; k <= K; k++){ 
        b = num;
        c = k;
        /* 自然数 a > b を確認・入替 */
        if (b < c) {
          tmp = b;
          b = c;
          c = tmp;
        }

       /* ユークリッドの互除法 */
       r = b % c;
       while (r != 0) {
         b = c;
         c = r;
         r = b % c;
       }

       ans += c;
      }
    }
  }
  printf("%llu", ans);
  return 0;
}
