#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1000000000
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)
#define repM(i, n) for (int i = n; i > 0; i--)

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int main() {
    int K;
    cin >> K;
    ll sum = 0;
    repX(a,K+1,1){
        repX(b, K+1,1){
            repX(c, K+1,1){
                sum += gcd(a,gcd(b,c));
            }
        }
    }
    cout << sum << endl;

    return 0;
}