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