#include <stdio.h>
int main(){
  int N,i,j,k,l,sum,a,b,r,x;
  scanf("%d",&N);
  sum=0;
  for(i=1;i<=N;i++){
    for(j=i;j<=N;j++){
      for(k=j;k<=N;k++){
        if(i==k) x=1;
        else if(i==j || j==k) x=3;
        else x=6;
        a=j;
        b=i;
        r=a%b;
        while(r!=0){
          a=b;
          b=r;
          r=a%b;
        }
        a=k;
        r=a%b;
        while(r!=0){
          a=b;
          b=r;
          r=a%b;
        }
        sum=sum+b*x;
      }
    }
  }
  printf("%d",sum);
  return 0;
}