#include <iostream>
using namespace std;

int k;

int gcd(int a, int b) {
    if (b == 0) 
        return a; 
    return gcd(b, a % b);
} 

int main() {
	cin >> k;
	long long ans = 0;
	for (int a=1; a<=k; a++) {
		for (int b=1; b<=k; b++) {
			for (int c=1; c<=k; c++) {
				ans += gcd(a, gcd(b, c));
			}
		}
	}
	cout << ans;
}