#include <stdio.h>

int gcd(int x,int y){
  int n1,n2,k1;
  if(x>y){
    n1=x;  n2=y;
  }
  else{
    n1=y;  n2=x;
  }
  while((n1%n2)!=0){
    k1=n1;
    n1=n2;
    n2=(k1%n2);
  }
  return n2;
}

void main(){
  int i,j,k,n,g;
  long sum=0;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      for(k=1;k<=n;k++){
        g=gcd(i,j);
        g=gcd(g,k);
        sum+=g;
      }
    }
  }
  printf("%ld",sum);
}