#include<stdio.h>

int gcd(int i,int j,int k,int n);

int main() {
  int i,j,k,n;
  long long sum = 0;
  scanf("%d",&n);
  for(i = 1;i <= n;i++) {
    for(j = 1;j <= n;j++) {
      for(k = 1;k <= n;k++) {
        sum += gcd(i,j,k,n);
      }
    }
  }
  printf("%lld\n",sum);
}

int gcd(int i,int j,int k,int n) {
  int max,a,maxgcd;
  if(i < j) {
    max = j;
  } else {
    max = i;
  }
  if(max < k) {
    max = k;
  }
  for(a = max;a >= 1;a--) {
    if(i % a == 0 && j % a == 0 && k % a == 0) {
      maxgcd = a;
      break;
    }
  }
  return maxgcd;
}
