#include <stdio.h>

int main(void){
    int K,a,b,c,r,tmp,sum=0,i,j,k;
    
    scanf("%d",&K);
    
    for(i=1;i<=K;i++){
        for(j=1;j<=K;j++){
            for(k=1;k<=K;k++){
                
                a=i;
                b=j;
                c=k;
                
                
                if(a<b){
                    tmp=a;
                    a=b;
                    b=tmp;
                }
                
                r=a%b;
                while(r!=0){
                    a=b;
                    b=r;
                    r=a%b;
                }
                
                
                if(b<c){
                    tmp=b;
                    b=c;
                    c=tmp;
                }
                
                r=b%c;
                while(r!=0){
                    b=c;
                    c=r;
                    r=b%c;
                }
                
                sum=sum+c;
            }
        }
    }
    
    printf("%d\n",sum);
    
    return 0;
}