int findGdc(int a, int b, int c){
    int min, gdc;
    if (a < b && a < c)
        min = a;
    else if (b < a && b < c)
        min = b;
    else
        min = c;

    for (int i=1; i <= min; i++) {
        if (a % i == 0 && b % i == 0 && c % i == 0)
            gdc = i;
    }
    return gdc;
}

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

    for (int i = 1; i <= k; i++){
        for (int j = 1; j <= k; j++){
            for (int t = 1; t <= k; t++){
                sum += findGdc(i, j, t);
            }
        }
    }
    printf("%d", sum);
}

