#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pi pair<int, int>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define deb(x) cout << #x << ":" << x << endl;
/* freopen("input.txt", "r", stdin); */
/* freopen("output.txt", "w", stdout); */
const ll inf = 1e17 + 7, MOD = 1e7 + 9;


int gcd(int a, int b) {
	if(b==0)
		return a;
	return gcd(b, a%b);
}

int main() {
	int k;
	cin >> k;
	ll sum = 0;
	for(int i=1;i<=k;i++)
		for(int j=1;j<=k;j++)
			for(int l=1;l<=k;l++)
				sum += gcd(i, gcd(j, l));
	cout << sum << "\n";
	return 0;
}
