/* C - Sum of gcd of Tuples (Easy) */

#include <stdio.h>

int getgcd(int a, int b){
  int r;
  r = a % b;
  if(r == 0) return b;
  else return getgcd(b, r);
}

int gcd(int a, int b, int c){
  return getgcd(getgcd(a, b), c);
}

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