#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Apr 12 21:00:01 JST 2020
 **/

signed main() {
    Int n;
    std::cin >> n;
    Int ans = 0;
    REP(a, 1, n + 1) {
        REP(b, 1, n + 1) {
            REP(c, 1, n + 1) {
                ans += std::gcd(a, std::gcd(b, c));
            }
        }
    }
    std::cout << ans << std::endl;
}
