#include<stdio.h>
int gcd(int i, int j, int k){
    int tmp, r, ans;
    if(i<j){
        tmp = i;
        i = j;
        j = tmp;
    }
    r = i % j;
    while(r!=0){
        i = j;
        j = r;
        r = i % j;
    }
    if(j<k){
        tmp = j;
        j = k;
        k = tmp;
    }
    ans = j % k;
    while(ans!=0){
        j = k;
        j = ans;
        ans = j % k;
    }
    return k;

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