#include <stdio.h>

    int gcd(int x, int y){
    int r = 1;
    while(r!=0){
        r = x%y;
        x = y;
        y = r;
    }
    return x;
}

int main(){
    int n;
    int a, b, c;
    int sum = 0;

    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        a = i;
        for(int j = 1; j <= n; j++){
            b = j;
            for(int k = 1; k <= n; k++){
                c = k;
                sum += gcd(gcd(a, b), c);
            }
        }
    }
    printf("%d", sum);

    }