#include<stdio.h>

int gcd(int a, int b, int c);

int main(void){

    int K;
    
    long int answer = 0;

    //入力部分
    scanf("%d",&K);

    //計算部分
    for(int a = 1; a <= K; a++){
        for(int b = 1; b <= K; b++){
            for(int c = 1; c <= K; c++){
                answer += gcd(a,b,c);
            }
        }
    }

    //出力部分
    //answer = gcd(2,2,2);
    printf("%ld\n",answer);
}

int gcd(a,b,c){
    int g=a;
    if(g>b)g=b;
    if(g>c)g=c;
    while(g!=1){
        if((a%g==0) && (b%g==0) && (c%g==0)){
            //printf("(%d,%d,%d)%d\n",a,b,c,g);
            break;
        }
        g--;
    }
    return g;
}