#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<tuple>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int gcd(int a, int b) {
	return b ? gcd(b, a%b) : a;
}
int gcd(int a, int b, int c) {
	return gcd(gcd(a, b), c);
}
int main() {
	int k;
	cin >> k;
	int ans = 0;
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			for (int l = 1; l <= k; l++) {
				ans += gcd(i, j, l);
			}
		}
	}
	cout << ans << endl;
	return 0;
}