#include<stdio.h>
int koyakusu(int a,int b)
{
  int r=1;
  while(r!=0){
    r=a%b;
    a=b;
    b=r;
  }
  
  return a;
}
int main(void)
{
  int x,y,z;
  int num=0;
  int n;
  
  scanf("%d", &n);
  
  for(x=1;x<=n;x++){
    for(y=1;y<=n;y++){
      for(z=1;z<=n;z++){
        num+=koyakusu(koyakusu(x,y),z);
      }
    }
  }
  printf("%d", num);
  
  return 0;
}
