#include <stdio.h>

int gcd(int a, int b)
{
    if (a == 0) {
	return b;
    }
    return gcd(b % a, a);
}

int gcd3(int a, int b, int c)
{
    int gcd_ab = gcd(a, b);
    return gcd(gcd_ab, c);
}

int main(void)
{
    int	k;
    int	ans = 0;

    if (fscanf(stdin, "%d", &k) != 1)
	return 0;

    for (int ia = 1; ia <= k; ia++) {
	for (int ib = 1; ib <= k; ib++) {
	    for (int ic = 1; ic <= k; ic++) {
		ans += gcd3(ia, ib, ic);
	    }
	}
    }

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

/*
 * vim:smartindent:sw=4:sts=4:co=84:nu:wm=78:
 */
