#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll dep(ll a,ll b){
	if(b==0){
		return a;
	}
	dep(b,a%b);
	return a;
}
ll gcd (unsigned int n1, unsigned int n2) {
    return (n2 == 0) ? n1 : gcd (n2, n1 % n2);
}
int main() {
	ll n;
	cin>>n;
	ll ans=0;
	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=n;j++){
			for(ll k=1;k<=n;k++){
				//cout << "k";
				ll now=gcd(max(k,j),min(k,j));
			//	cout << "k";
				ans+=gcd(max(now,i),min(now,i));
			}
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}