#include<stdio.h>

int kyouyaku(int a,int b){
  int tmp;
  if(a<b){
    tmp=a;
    a=b;
    b=tmp;
  }
  if(a%b==0)
    return b;
  return kyouyaku(b,a%b);
}

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