#include<stdio.h>
 
int gcd(int a,int b){
	if(b==0)
      return a;
  	return gcd(b,a%b);
}
 
int gcd2(int a,int b,int c){
  int t;
  t=gcd(a,b);
  return gcd(t,c);
}
 
int main(void){
	int n,i,j,k,t=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
    	for(j=1;j<=n;j++){
    		for(k=1;k<=n;k++){
    			t+=gcd2(i,j,k);
		    }
		}
	}

  printf("%d",t);
  return 0;
}