#include <iostream>
#include <math.h>
#include <vector>
#include <set>
#include <algorithm>
#include <iomanip>
#include <bitset>
#include <map>
typedef long long ll;
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define all(v) v.begin(), v.end()
#define ss second
#define ff first
#define pb push_back
#pragma GCC optimize("Ofast", "unroll-loops", "fast-math", "no-stack-protector")
#pragma GCC target("avx2")
using namespace std;
/*
string s;
vector < int > skobe;
ll mod = 998244353;
pair < pair < ll, ll >, pair < ll, ll > > ask(int l, int r) {
    if (l == r) return {{2, 2}, {2, 2}};
    int ind = skobe[l + 1] + 1;
    //cout << s[ind] << "- " << endl;
    auto k1 = ask(l + 1, skobe[l + 1]);
    auto k2 = ask(ind + 1, r - 1);
    pair < pair < ll, ll >, pair < ll, ll > > ans;
    if (s[ind] == '&') {
        ans.ff.ff = ((k1.ff.ff * k2.ff.ff) % mod) + ((k1.ff.ff * k2.ff.ss) % mod) + ((k1.ff.ss * k2.ff.ff) % mod);
        ans.ff.ss = ((k1.ff.ss * k2.ff.ss) % mod);
        ans.ss.ff = ((k1.ss.ff * k2.ss.ff) % mod) + ((k1.ss.ff * k2.ss.ss) % mod) + ((k1.ss.ss * k2.ss.ff) % mod);
        ans.ss.ss = ((k1.ss.ss * k2.ss.ss) % mod);
    }
    if (s[ind] == '|') {
        ans.ff.ff = ((k1.ff.ff * k2.ff.ff) % mod);
        ans.ff.ss = ((k1.ff.ff * k2.ff.ss) % mod) + ((k1.ff.ss * k2.ff.ff) % mod) + ((k1.ff.ss * k2.ff.ss) % mod);
        ans.ss.ff = ((k1.ss.ff * k2.ss.ff) % mod);
        ans.ss.ss = ((k1.ss.ff * k2.ss.ss) % mod) + ((k1.ss.ss * k2.ss.ff) % mod) + ((k1.ss.ss * k2.ss.ss) % mod);
    }
    if (s[ind] == '^') {
        ans.ff.ff = ((k1.ff.ff * k2.ff.ff) % mod) + ((k1.ff.ss * k2.ff.ss) % mod);
        ans.ff.ss = ((k1.ff.ff * k2.ff.ss) % mod) + ((k1.ff.ss * k2.ff.ff) % mod);
        ans.ss.ff = ((k1.ss.ff * k2.ss.ff) % mod) + ((k1.ss.ss * k2.ss.ss) % mod);
        ans.ss.ss = ((k1.ss.ff * k2.ss.ss) % mod) + ((k1.ss.ss * k2.ss.ff) % mod);
    }
    ans.ff.ff %= mod;
    ans.ff.ss %= mod;
    ans.ss.ff %= mod;
    ans.ss.ss %= mod;
    return ans;
}
ll step(ll x, ll a) {
    if (a == 0) return 1;
    if (a == 1) return x;
    if (a % 2 == 0) return step((x * x) % mod, a / 2);
    else return (step(x, a - 1) * x) % mod;
}
void solve() {
    cin >> s;
    int n = s.size();
    skobe.clear();
    skobe.resize(n);
    fori(n) skobe[i] = i;
    vector < int > buf;
    for (int i = n - 1; i >= 0; i--) {
        if (s[i] == ')') buf.pb(i);
        else if (s[i] == '(') {
            skobe[i] = buf.back();
            buf.pop_back();
        }
    }
    int cnt = 0;
    fori(n) if (s[i] == '#') cnt++;
    ll bib = step(4, cnt * 2);
    bib = step(bib, mod - 2);
    auto ans = ask(0, n - 1);
    cout << (ans.ff.ff * ans.ss.ff * bib) % mod << " ";
    cout << (ans.ff.ss * ans.ss.ss * bib) % mod << " ";
    cout << (ans.ff.ff * ans.ss.ss * bib) % mod << " ";
    cout << (ans.ff.ss * ans.ss.ff * bib) % mod << " ";
    cout << endl;
}
/// ((#|#)|((#&#)^#))
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--) solve();
}*/
int main() {
    int k;
    cin >> k;
    ll sum = 0;
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            for (int c = 1; c <= k; c++) {
                sum += __gcd(a, __gcd(b, c));
            }
        }
    }
    cout << sum;
}


Measured memory_bytes: 3620