#include <stdio.h>

int gcd(int, int);

int main() 
{

    int num;
    int sum = 0;

    scanf("%d", &num);

    for( int i = 1; i <= num; i++ ){
        for( int j = 1; j <= num; j++ ){
            for( int k = 1; k <= num; k++ ){
                sum += gcd(gcd(i,j),k);
            }
        }
    }

    printf("%d", sum);
    
    return 0;

}

int gcd(int a, int b){
    if (b == 0){
        return a;
    }

    return gcd(b, a%b);
}

