#include <iostream>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)

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

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