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

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