#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>

int gcd2(int a,int b)
{
  int r=1;
  while(r!=0){
    r=a%b;
    a=b;
    b=r;
  }
  return a;
}

int gcd3(int a,int b, int c)
{
  int t,ans;
  t=gcd2(a,b);
  ans=gcd2(t,c);
  return ans;

}
int main(void)
{
  int k,s,t,u,ans=0;
  scanf("%d",&k);

  for(s=1;s<=k;s++){
    for(t=1;t<=k;t++){
      for(u=1;u<=k;u++){
        ans+=gcd3(s,t,u);
      }
    }
  }
  printf("%d",ans);


	return 0;
}
