#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <stack>
#include <deque>
#include <ctime>
#include <random>
#include <cassert>
#include <cmath>
#include <climits>
#include <queue>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <chrono>


/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
*/


#define int long long
#define fi(a,b) for (int i=a;i<b;i++)
#define fj(a,b) for (int j=a;j<b;j++)
#define fk(a,b) for (int k=a;k<b;k++)
#define fi1(a,b) for (int i=a-1;i>=b;i--)
#define fj1(a,b) for (int j=a-1;j>=b;j--)
#define fk1(a,b) for (int k=a-1;k>=b;k--)
#define fx(x,a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound


#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()


using namespace std;
typedef long long ll;
typedef char ch;
typedef string str;
typedef vector <long long> vl;
typedef vector <int> vi;
typedef vector<vector<long long>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<pair<ll, ll>>> vvpll;
typedef vector<vector<pair<int, int>>> vvpii;
typedef vector<char> vch;
typedef vector<vector<char>> vvch;
typedef vector<string> vs;
typedef map<ll, ll> mll;
typedef map<int, int> mii;
typedef map<int, ch> mich;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef unsigned long long ull;


string to_string(long long x) {
    string s;
    bool neg = x < 0;
    x = abs(x);
    do {
        s += char('0' + x % 10);
        x /= 10;
    } while (x != 0);
    if (neg)
        s += '-';
    reverse(s.begin(), s.end());
    return s;
}

ll powmod(ll a, ll b, ll mod) {
    if (b == 0 || a == 1)
        return mod == 1 ? 0 : 1;

    ll k = powmod(a, b / 2, mod);
    k = k * k % mod;
    if (b & 1)
        k = k * a % mod;
    return k;
}

ll pow10(ll a, ll b) {
    if (b == 0 || a == 1)
        return 1;
    ll k = pow10(a, b / 2);
    k *= k;
    if (b & 1)
        k *= a;
    return k;
}

ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

bool is_prime(ll n) {
    ll bound = sqrt(n);
    ll d = 2;
    while (d <= bound && n % d != 0)
        ++d;
    return d * d > n;
}


const int MOD = 1000000007;
const int MOD2 = 1000000009;
const int BASE = 257;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 100010;
const double EPS = 1e-9;
const int DI[]{1, -1, 0, 0};
const int DJ[]{0, 0, 1, -1};


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



int32_t main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int k;
    cin >> k;
    int sum = 0;
    fi(1, k + 1) {
        fj(1, k + 1) {
            rep(kk, 1, k + 1) {
                sum += gcd(gcd(i, j), kk);
            }
        }
    }
    cout << sum;
}


Measured memory_bytes: 3644