#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main() {
	freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL); 
	int n;
	cin>>n;

	ll ans = 0;

	for(int i = 1; i <= n; ++i){
		for(int j = 1; j  <= n; ++j){
			for(int k = 1; k <= n; ++k){
				ans += __gcd(k, __gcd(i,j));
			}
		}
	}

	cout<< ans << endl;

}
