/**
 * Title:
 * Url:
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

ll gcd(ll a, ll b) {
    if(a==b) return a;
    if(a<b) {
        ll tmp = a;
        a = b;
        b = tmp;
    }
    ll r = a%b;
    while(r!=0) {
        ll tmp_r = r;
        r = b % r;
        b = tmp_r;
    }
    return b;
}

// 最小公倍数
ll lcm(ll a, ll b) {
    if(a==b) {
        return a;
    }
    ll gcd_a_b = gcd(a, b);
    return a/gcd_a_b*b;
}

int main() {
    ll k; cin >> k;
    ll sum = 0;
    for(ll i=1; i<=k; i++) {
        for(ll j=1; j<=k; j++) {
            for(ll l=1; l<=k; l++) {
                sum += gcd(gcd(i, j), l);
            }
        }
    }
    cout << sum << endl;

    return 0;
}