#include <stdio.h>

int euclid( int a, int b )
{
    int temp;

    if( a < b ) { temp = a; a = b; b = temp; }
    if( b < 1 ) return -1;

    if( a % b == 0 ) return b;
    return euclid( b, a % b );
}


int main(void){
    int a, temp, num, sum, i, j, k;
    scanf("%d", &a);

    sum = 0;

    for(i = 1; i <= a; i++){
        for(j = 1; j <= a; j++){
            for(k = 1; k <= a; k++){
                temp = euclid(i, j);
                num = euclid(temp, k);
                sum += num;
            }
        }
    }

    printf("%d\n", sum);

    return 0;

}