#include <bits/stdc++.h>
 
using namespace std;
 
#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(v) v.begin(), v.end()
#define PB push_back
#define F first
#define S second
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
 
const ll MOD = 1e9+7;
 
int gcd(int a, int b){
	return (b ? gcd(b, a%b) : a);
}

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
 
	int n; cin >> n;
	ll sum = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			for(int k = 1; k <= n; k++){
				sum += gcd(gcd(i, j), k);
			}
		}
	}

	cout << sum << '\n';
 
	return 0;
}