#include<stdio.h>

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

int main(){
    int k;
    scanf("%d",&k);

    int ans = 0;

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