#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>

using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for (ll i = 0; i < (n); ++i)

ll gcd(ll a, ll b){
    if (a%b) return gcd(b,a%b);
    else return b;
}

int main() {
    ll k;
    cin >> k;
    ll sum = 0;
    rep(l,k){
        rep(m,k){
            rep(n,k){
                sum += gcd( gcd( l+1 , m+1 ) , n+1 );

            }
        }
    }
    cout << sum << endl;
    return 0;
}