#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);
            }
        }
    }

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

int gcd(a,b,c){
    int gcd;
    int g = 1;
    while(g<=a||g<=b||g<=c){
        if(a%g==0 && b%g==0 && c%g==0)gcd=g;
        g++;
    }
    return gcd;
}