#include <stdio.h>

long gcd(long a, long b){
  if(a % b == 0) return b;
  else return gcd(b, a % b);
}

int main(void)
{
  int K;
  int a, b, c;
  scanf("%d", &K);
  long ans = 0;

  ans += K * (K + 1) / 2;
  //a < b < c
  for(a = 1; a <= K-1; a++){
    for(b = a + 1; b <= K; b++){

      long buf = gcd(a, b);

      ans += buf * 6;//aab/aba/baa/bba/bab/abb

      for(c = b + 1; c <= K; c++){
        ans += gcd(buf, c) * 6;//abc/acb/bac/bca/cab/cba
      }
    }
  }
  printf("%ld\n", ans);
	return 0;
}
