#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int64 i = 1; i <= (int64)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
int64 gcd(int64 a, int64 b) {
	return b != 0 ? gcd(b, a % b) : a;
}
void solve() {
	int64 k; cin >> k;
	int64 ans = 0;
	repn (a, k) {
		repn (b , k) {
			repn (c, k) {
				int64 tmp = gcd(c, gcd(a, b));
				ans += tmp;
			}
		}
	}
	cout << ans << endl;
	return;
}

int main() {
	solve();
  return 0;
}