# include <bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
# define int long long
  
using namespace std;
  
const int N = 1e3 + 7;
const int INF = 1e18;
const int mod = 1e9 + 7; 
  
int32_t main() {
    speed;
	int k, ans = 0;
	cin >> k;

	for ( int a = 1; a <= k; a++ ) {
		for ( int b = 1; b <= k; b++ ) {
			for ( int c = 1; c <= k; c++ ) {
				ans += __gcd( __gcd( a, b), c );
			}
		}
	}
	cout << ans;
}