#include <stdio.h>

int gcd(int, int);

int main(){
    int K;
    scanf("%d", &K);
    long sum = 0;

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

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

    return 0;
}

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