#include <stdio.h>
int fuction(int a,int b)
{
  int c=1;
  while(c!=0){
    c=a%b;
    a=b;
    b=c;
  }
  return a;
}
int main()
{
  int n;
  int i,j,k;
  int sum=0;
   scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      for(k=1;k<=n;k++){
            sum=sum+fuction(fuction(i,j),k);
      }
    }
  }
  printf("%d",sum);
  return 0;
}