#include<stdio.h>

int gcd(int a,int b){
  int lar,sma;
  if(a>b){
    lar = a;
    sma = b;
  }else{
    lar = b;
    sma = a;
  }
  if(lar%sma == 0){
    return sma;
  }else{
    return gcd(b,a%b);
  }
}

int main(){
  int k;
  char buf[10];

  if(fgets(buf,sizeof(buf),stdin)!=NULL){
    sscanf(buf,"%d",&k);
  }

  int x,y,z;
  int sum;
  for(x=1;x<=k;x++){
    for(y=1;y<=k;y++){
      for(z=1;z<=k;z++){
        sum += gcd(gcd(x,y),z);
      }
    }
  }

  printf("%d\n",sum);
  return 0;
}
