#include<stdio.h>

int gcd(int a0, int a1){
    int a, b, r;
    a=a0;
    b=a1;
    while(b!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}

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

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