#include <stdio.h>


int gcd(int a,int b,int c){
    int d,e;
    d = gc(a,b);
    e = gc(c,d);
    return e;
}

int gc(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(){
    int n,i,j,k,sum;
    scanf("%d",n);
    sum =0;
    for(i=1;i<n+1;i++){
        for(j=1;j<n+1;j++){
            for(k=1;k<n+1;k++){
                sum = sum + gcd(i,j,k);
            }
        }
    }
    printf("%d",sum);
    return 0;
}

