#include<stdio.h>

int gcd(int a,int b,int c){
    int max,min,i;
    if(a>b&&a>c){
        if(b>c){
            min = c;
        }
        else
            min = b;
        max = a;
    }
    else if(b>a&&b>c){
        if(a>c){
            min = c;
        }
        else
            min = a;
        max = b;
    }
    else{
        if(a>b){
            min = b;
        }
        else
            min = a;
        max =c;
    }

    for(i=max;i>=1;i--){
        if(a%i==0&&b%i==0&&c%i==0){
            return i;
        }
    }
    return 0;
}

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