#include<stdio.h>
int gcd(int x, int y){
  if(x<y){
    int w=x;
x=y;
y=w;
}
if(x%y!=0)return gcd(y,x%y);
else return y;
}
int main(void){
  int k,sum=0;
scanf("%d",&k);
for(int a=1;a<=k;a++){
	for(int b=1;b<=k;b++){
      for(int c=1;c<=k;c++){
int ab=gcd(a,b);
sum+=gcd(ab,c);
}
    }
}
  printf("%d",sum);
  return 0;
}

