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