#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(17) << res << endl;

ll gcd(ll a, ll b){
    return b?gcd(b, a%b):a;
}

int main() {
    ll k;
    cin >> k;
    ll res = 0;
    for (ll a = 1; a <= k; ++a) {
        for (ll b = 1; b <= k; ++b) {
            auto ab = gcd(a,b);
            for (ll c = 1; c <= k; ++c) {
                res += gcd(ab, c);
            }
        }
    }
    cout << res << endl;
}
