#include<stdio.h>
int gcd(int a,int b){
    int r,tmp;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}
int main(void)
{
    int n,i,j,k,b,c,total=0;
    scanf("%d",&n);

    for(i=1;i<n+1;i++){
        for(j=1;j<n+1;j++){
            for(k=1;k<n+1;k++){
                b=gcd(i,j);
                c=gcd(k,b);
                total = total +c;
            }
        }
    }
    printf("%d\n",total);
    return 0;
}
