#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
const int N = 200001;
using namespace std;




int main() {
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    int n;
    cin >> n;
    int a[n + 1][n + 1];
    for (int i = 1; i < n + 1; i++) {
        for (int j = 1; j < n + 1; j++) {
            a[i][j] = __gcd(i, j);
        }
    }

    ll ans = 0;
    for (int i = 1; i < n + 1; i++) {
        for (int j = 1; j < n + 1; j++) {
            for (int k = 1; k < n + 1; k++) {
                ans += a[i][a[j][k]];
            }
        }
    }

    cout << ans;

}