#include <stdio.h>

int gcd(int x,int y){ 

        if(y==0){
                return x;
        }else{
                return gcd(y,x%y);
        }   
}


int main(void){

        int i,j,k,n;
        int sum = 0;

        scanf("%d",&n);

        for(i=1;i<=n;i++){
                for(j=1;j<=n;j++){
                        for(k=1;k<=n;k++){
                                int tmp = gcd(i,j);
                                sum += gcd(tmp,k);
                        }   
                }   
        }   
printf("%d\n",sum);
return 0;
}

