#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int main() {
	int k;
	cin >> k;
	ll ans = 0;
	for(int a = 1; a <= k; a++){
		for(int b = 1; b <= k; b++){
			for(int c = 1; c <= k; c++){
				ans += gcd(gcd(a, b), c);
			}
		}
	}
	
	cout << ans << endl;
	return 0;
}