#include <iostream>
using namespace std;

typedef long long LL;

#define REP(i, n) for(LL i = 0; i < (LL)(n); i++)
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

template<typename T>
T gcd(T a, T b) {
    T r, temp;

    while(1) {
        if(a < b) {
            temp = a;
            a = b;
            b = temp;
        }
        if(b < 1) continue;

        while((r = a % b) != 0) {
            a = b;
            b = r;
        }
        return b;
    }
}

int main() {
    LL K;
    cin >> K;
    LL res = 0;
    FOR(i, 1, K + 1) {
        FOR(j, 1, K + 1) {
            FOR(k, 1, K + 1) {
                res += gcd(gcd(i, j), k);
            }
        }
    }
    cout << res << endl;
    return 0;
}
