#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()

const int INF = 100000002;
int gcd_2(int a, int b){
	if(b == 0) return a;
	return gcd_2(b, a%b);
}

int gcd_3(int a, int b, int c){
	int tmp = gcd_2(a, b);
	return gcd_2(tmp, c);
}

int main(){
	ll ans = 0;
	int k; cin >> k;
	for (int i=1; i<=k; i++){
		for (int j=1; j<=k; j++){
			for (int h=1; h<=k; h++){
				ans += gcd_3(i, j, h);
			}
		}
	}
	cout << ans << endl;
}