#include <bits/stdc++.h>

using namespace std;

int main() {
    int N;
    cin >> N;

    int ans = 0;
    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= N; ++j) {
            for (int k = 1; k <= N; ++k) {
                ans += __gcd(i, __gcd(j, k));
            }
        }
    }
    cout << ans << endl;
    return 0;
}
