#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
typedef long long  ll;
typedef long double lb;
using namespace std;
int main() {
	int n;
	cin >> n;
	int sum = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1;j<= n; j++){
			int a = max(i, j);
			int b = min(i, j);
			int r = a % b;
			while (r != 0){
				a = b;
				b = r;
				r = a % b;
			}
			for (int l = 1; l <= n; l++) {
				int c = max(b, l);
				int d = min(b, l);
				int x = c % d;
				while (x != 0) {
					c = d;
					d = x;
					x = c % d;
				}
				sum += b;
			}
		}
	}
	cout << sum << endl;
}




