#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void swap(int a,int b){
    int tmp;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
}

int gcddi(int a, int b){
    swap(a,b);
    // printf("swap");
    int r;
    r = a%b;

    while(r != 0){
        // printf("%d\n",r);
        a = b;
        b = r;
        r = a%b;
    }
    return b;
}

int gcdtri(int a,int b, int c){
    int former = gcddi(a,b);
    // printf("gcdtri");

    return gcddi(former,c);
}


int main(void){
    int k,i,j,l;
    long int sum = 0;

    scanf("%d",&k);
    for(i=1;i<=k;i++){
        for(j=1;j<=k;j++){
            for(l=1;l<=k;l++){
                sum += gcdtri(i,j,l);
            }
        }
    }

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