#include <stdio.h>

int g(int x, int y) {
   int t;

   while ((t=x%y)!=0) {
      x=y;y=t;
   }
   return y;
}

int main(){
   int i,j,k,l,s,gcd[201][201];

   scanf("%d",&k);
   for (i=1;i<=k;i++)
      for (j=1;j<=k;j++) gcd[i][j]=g(i,j);
   s=0;
   for (i=1;i<=k;i++)
      for (j=1;j<=k;j++) 
        for (l=1;l<=k;l++) s+=gcd[gcd[i][j]][l];
   printf("%d\n",s);
   return 0;
}
