#include <stdio.h>

int getgcd(int n, int m)
{
int r;
if (n > m) {
int t = m;
m = n;
n = t;
}
while ((r = m % n) != 0) {
m = n;
n = r;
}
return n;
}


int main(void){
int k,a,b,c;
  long int sum=0;
  scanf("%d", &k);
  for(a=1;a<=k;a++){
      for(b=1;b<=k;b++){
          for(c=1;c<=k;c++){
          sum += getgcd(getgcd(a, b), c);
          } 
      }
  }
  printf("%ld\n", sum);
  return 0;
}