#include <stdio.h>
#include <stdlib.h>

int gcd2(int a, int b){
    if(b == 0)
       return a;

    return gcd2(b, a%b);
}

int gcd3(int a, int b, int c){
    return gcd2(gcd2(a, b), c);
}

int main(void){
    int k, ii1, ii2, ii3, sum;
    sum=0;
    scanf("%d", &k);
    for(ii1=1; ii1<=k; ii1++){
        for(ii2=1; ii2<=k; ii2++){
            for(ii3=1; ii3<=k; ii3++){
                sum += gcd3(ii1, ii2, ii3);
            }
        }
    }

    printf("%d\n", sum);
}
