#include <stdio.h>
#include <stdint.h>

uint64_t _gcd(int x, int y) {
        if (x == 0) {
                return y;
        }

        return _gcd(y % x, x);
}

uint64_t gcd(int x, int y) {
        if (x > y) {
                return _gcd(y, x);
        } else {
                return _gcd(x, y);
        }
}

uint64_t solve(int k) {
        int a, b, c;
        uint64_t ret = 0;
        uint64_t gcd_a_b;

        for (a = 1; a <= k; ++a) {
                for (b = 1; b <= k; ++b) {
                        gcd_a_b = gcd(a, b);
                        for (c = 1; c <= k; ++c) {
                                ret += gcd(gcd_a_b, c);
                        }
                }
        }

        return ret;
}

int main() {
        int k;
        int rc;

        rc = scanf("%d", &k);
        if (rc == 0) {
                perror("scanf");
                return 1;
        }

        printf("%lld\n", solve(k));

        return 0;
}
