#include <stdio.h>
int getgcd(int n, int m)
{
int r;
if (n > m) {
int t = m;
m = n;
n = t;
}
while ((r = m % n) != 0) {
m = n;
n = r;
}
return n;
}

int main(void)
{
int k;
  scanf("%d", &k);

int gcd;
  long long ans = 0;

for(int a = 1;a < k+1;a++){
	for(int b = 1;b< k+1;b++){
	for(int c = 1;c < k+1;c++){
	gcd = getgcd(getgcd(a, b), c);
     ans += gcd;
	}
	}
}

printf("%lld\n",ans);
return 0;
}