#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);
int gcd3(int a, int b, int c) {
    int ab = __gcd(a, b);
    return __gcd(ab, c);
}
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 += gcd3(i, j, k);
    }
    cout << ans << endl;

    return 0;
}


