#include <stdio.h>

int gcd(int a, int b, int c){
    int gcd;
    while(a%b!=0){
        int tmp=a;
        a=b;
        b=tmp%b;
    }
    gcd=b;
    while(c%gcd!=0){
        int tmp=c;
        c=gcd;
        gcd=tmp%gcd;
    }
    return gcd;

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