#include <iostream>

using ll = long long;
#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using namespace std;

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

int main(void) {
    int n;
    cin >> n;

    ll sum = 0;
    // 3つ同じ
    repe(val, 1, n) {
        // printf("(%d, %d, %d) : %d", val, val, val, val);
        sum += val;
    }

    // 2つ同じ
    ll tsum = 0;
    repe(val1, 1, n) {
        repe(val2, val1 + 1, n) { tsum += gcd(val1, val2); }
    }

    sum += 6 * tsum;

    // 全部違う
    tsum = 0;
    repe(val1, 1, n) {
        repe(val2, val1 + 1, n) {
            repe(val3, val2 + 1, n) { tsum += gcd(gcd(val1, val2), val3); }
        }
    }
    sum += 6 * tsum;

    cout << sum << endl;

    return 0;
}
