#include <stdio.h>
int gcd(int x,int y){
  int tmp;
  if(y>x){
    tmp=y;
    y=x;
    x=tmp;
  }
  if(y==0){
    return x;
  }else{
    return gcd(y,x%y);
  }
}

int main(){
  int n,a,b,c,gcd_1,gcd_2;
  long result=0;
  
  scanf("%d",&n);
  
  for(a=1;a<=n;a++){
    for(b=1;b<=n;b++){
      for(c=1;c<=n;c++){
        gcd_1=gcd(a,b);
        gcd_2=gcd(gcd_1,c);
        //printf("%d %d\n",gcd_1,gcd_2);
        result+=gcd_2;
      }
    }
  }
  printf("%ld",result);
}