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