#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
	int n;
	cin >> n;
	ll ans=0;
	rep(i,n) rep(j,n) rep(k,n) {
		int t1 = i+1,t2=j+1,t3=k+1;
		int t4 = __gcd(__gcd(t1,t2), t3);
		ans += t4;
	}
	cout << ans << endl;


  return 0;
}