#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define f first
#define s second

using namespace std;

typedef long long ll;
const int INF = 1e9;
const ll INFl = 1e18;

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef set<int> si;
typedef map<int,int> mii;
typedef unordered_map<int,int> umii;
typedef queue<int> qi;

vi V;

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int k; cin >> k;
	ll sum = 0;
	for (int i = 1; i <= k; i ++) {
		for (int j = 1; j <= k; j ++) {
			for (int h = 1; h <= k; h ++) {
				int x = __gcd(i, j);
				int y = __gcd(h, x);
				sum += y;
			}
		}
	}
	cout << sum << '\n';
}
