#include<stdio.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))

static inline int gcd(int a,int b){
    int armin = min(a,b);
    int armax = max(a,b);
    int r;
    while(armin){
        r = armax;
        r %= armin;
        armax = armin;
        armin = r;
    }
    return armax;
}

int main(void){
    int k;
    scanf("%d",&k);
    long long ans = 0;
    register int i,j,l;
    for(i = 1;i <= k;i++)for(j = 1;j <= k;j++)for(l = 1;l <= k;l++)ans += gcd(i,gcd(j,l));
    printf("%lld",ans);
}