#include<stdio.h>

int gcd(int n, int m){
    int r;
    if (n > m){
        int t = m;
        m = n;
        n = t;
    }
    while ((r = m % n) != 0){
        m = n;
        n = r;
    }
    return n;
}

int main(void){

    int K,i,j,k;
    int ans = 0;

    scanf("%d",&K);
    for(i = 1;i <= K;i++){
        for(j = 1;j <= K;j++){
            for(k = 1;k <= K;k++){
                ans += gcd(gcd(i,j),k);
            }
        }
    }

    printf("%d\n",ans);
    return 0;
}