#include <bits/stdc++.h>
using namespace std;
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using vl = vector<long long>;
using P = pair<long long,long long>;

ll gcd(ll a,ll b,ll c){
	while(true){
		if(a < b)swap(a,b);
		if(!b)break;
		a %= b;
	}
	ll d = a;
	while(true){
		if(c < d)swap(c,d);
		if(!d)break;
		c %= d;
	}
	return c;
}

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