#include<bits/stdc++.h>
using namespace std;

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int k;
    cin >> k;
    int64_t res = 0;
    for (int i = 1; i <= k; ++i) {
    	for (int j = 1; j <= k; ++j) {
    		for (int x = 1; x <= k; ++x) {
    			res += __gcd(i, __gcd(j, x));
    		}
    	}
    }
    cout << res << '\n';
}