#include <stdio.h>
int euclide(int a,int b){
    int max,min,tmp;
    if(a<=b){//代入
        max=b;
        min=a;
    }else{
        max=a;
        min=b;
    }

    while(1){
        if(max % min == 0){
            return min;
        }
        //printf("max=%d min=%d max %% min=%d \n",max,min,max%min);
        max = max % min;
        tmp = max;
        max = min;
        min = tmp;
    }
}
int main(void)
{
    int n;
    int i,j,k;;
    unsigned long int sum=0;
    scanf("%d",&n);

    for(i=1;i<=n;i++){
        for(j=i;j<=n;j++){
           for(k=j;k<=n;k++){
                //printf("a=%d b=%d c=%d\n",i,j,k);
                if(i==j && j==k){
                    sum += euclide(euclide(i,j),k);    
                }else{
                    sum += euclide(euclide(i,j),k) * 3;
                }  
                //printf("%ld\n",sum);         
            }
        }
    }

    printf("%ld\n",sum);
    return 0;
}
