#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

typedef long long int llint;

int K;

int dp[201][201];

int gcd(int a, int b) {
	if (dp[a][b] != 0) { return dp[a][b]; }
	if (b == 0) { 
		return a;
	}
	return dp[a][b] = gcd(b, a % b);
}

int main() {
	cin >> K;
	llint sum = 0;
	for (int i = 1; i <= K; i++) {
		for (int j = 1; j <= K; j++) {
			for (int k = 1; k <= K; k++) {
				sum += gcd(i, gcd(j, k));
			}
		}
	}
	cout << sum << endl;
}