#include <stdio.h>

int gcd(int N, int W)
{
    int amari = N % W;
    
    if (amari == 0) {
        return W;
    }
    
    return gcd(W, amari);
}

int main(void)
{
    int K;
    int a, b, c;
    int sum = 0;
    
    scanf("%d", &K);
    
    for (a = 1; a <= K; a ++) {
        for (b = 1; b <= K; b ++) {
            for (c = 1; c <= K; c ++) {
                sum += gcd(gcd(a, b), c);
            }
        }
    }
    
    printf("%d\n", sum);
    
    return 0;
}