#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

int gcd(int a, int b) {
    if (!a)
        return b;
    return gcd(b % a, a);
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int k;
    cin >> k;
    vector <vector <int>> g(k + 1, vector <int> (k + 1));
    forn (i, 1, k + 1)
        forn (j, 1, k + 1)
            g[i][j] = gcd(i, j);
    long long ans = 0;
    forn (a, 1, k + 1) {
        forn (b, 1, k + 1) {
            forn (c, 1, k + 1) {
                ans += g[g[a][b]][c];
            }
        }
    }
    cout << ans;
    return 0;
}