#include<stdio.h>
#include<math.h>
int main(void){
  int a,b,c;
  int input;
  unsigned int sum = 0;
  scanf("%d",input);
  for(a = 1;a <= input;a++){
    for(b = 1;b <= input;b++){
      for(c = 1;c <= input;c++){
        sum += gcd(a,b,c);
      }
    }
  }
  return 0;
}
    