#include <stdio.h>

int gcd(int p, int q){
  while(q != 0){
    int r = p % q;
    p = q;
    q = r;
    }
    return p;
    }


int main(void){
 int k,i,j,t,sum=0,x;
 (void)scanf("%d",&k);
for(i=1;i<=k;i++){
  for(j=1;j<=k;j++){
    for(t=1;t<=k;t++){
      x=gcd(gcd(i,j),t);
      sum+=x;
    }
  }
}
printf("%d\n",sum);
return 0;
}