#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

int dp[201][201] = {0};

int gcd(int a, int b){
	if(dp[a][b] != 0) return dp[a][b];
	if(dp[b][a] != 0) return dp[b][a];
    if(b == 0) {
		dp[a][b] = a;
		dp[b][a] = a;
		return a;
	}
	dp[a][b] = gcd(b, a%b);
	dp[b][a] = gcd(b, a%b);
    return gcd(b, a%b);
}

int main() {
	cin >> K;
	ll _sum = 0;
	rep(i, K){
		rep(j, K){
			rep(k, K){
				_sum += gcd(i+1, gcd(j+1, k+1));
			}
		}
	}
	cout << _sum;
}
