#include<stdio.h>
int gcd(int x, int y){
  while(y!=0){
    int r=x%y;
    x=y;
    y=r;}
  return x;
}
int main(void){
  int K;
  int i,j,l;
  int wa=0;
  scanf("%d",&K);
  for(i=1;i<=K;i++){
    for(j=1;j<=K;j++){
      for(l=1;l<=K;l++){
        wa=wa+gcd(gcd(i,j),l);}
    }
  }
  printf("%d",wa);
  return 0;
}