#include <iostream>
using namespace std;

int gcd(int p, int q) {
    if (p % q == 0) {
        return q;
    }
    return gcd(q, p % q);
}

int main() {
    int k;
    int ans = 0;
    cin >> k;

    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= k; j++) {
            for (int l = 1; l <= k; l++) {
                ans += gcd(i, gcd(j, l));
            }
        }
    }
    cout << ans << endl;
}