#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int cmp(const void *a,const void *b){
    if(*(int*)a>*(int*)b){return 1;}
    else if(*(int*)a<*(int*)b){return -1;}
    else {return 0;}
}


int gcd(int a,int b){
    int aa=a;
    int bb=b;
    int cc;
for(;;){
    if(aa%bb==0){return bb;}
    else{cc=aa%bb;aa=bb;bb=cc;}
}

}

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