#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stack>

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

int memo[210][210];
int gcd(int a, int b){ return (a%b ? gcd(b, a%b): b);}

using namespace std;
int main() {
	int n;
	cin >> n;
	long long res = 0;
	for (int i = 0; i < 210; i++){
		for (int j = 0; j < 210; j++){
			memo[i][j] = 10000;
		}
	}
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= n; j++){
			int a, b;
			if (memo[i][j] != 10000){
				a = memo[i][j];
			} else {
				memo[i][j] = gcd(i, j);
				a = memo[i][j];
			}
			for (int k = 1; k <= n; k++){
				if (memo[a][k] != 10000){
					b = memo[a][k];
				} else {
					memo[a][k] = gcd(a, k);
					b = memo[a][k];
				}
				res += b;
			}
		}
	}

	cout << res << endl;


}
