# include <stdio.h>
# include <string.h>
# include <stdlib.h>
int gcd (int a,int b){
	if(a%b==0) return b;
	if(b%a==0) return a;
	if (a>b) return gcd(b,a%b);
	return gcd(a,b%a);
}
int main(){
	int i,j,k,n,a,b;
	long long int ans=0;
	scanf ("%d",&n);
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			for(k=1;k<=n;k++){
				a=gcd(i,j);
				b=gcd(a,k);
				ans+=b;
			}
		}
	}
	printf ("%lld\n",ans);
	return 0;
}