#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define INF 100000000
using namespace std;
const int mod = 1000000007;

int gcd(int a, int b)
{
    if (a % b == 0)
    {
        return(b);
    }
    else
    {
        return(gcd(b, a % b));
    }
}
int main() {

    int64_t N, ans = 0;
    cin >> N;
    //vector<int> A(N);
    //for(int i=0; i<N; i++){cin>>A[i];}
    //vector<vector<int>> A(N,vector<int>(M));
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            for (int k = 1; k <= N; k++) {
                ans += gcd(gcd(i, j), k);
            }
        }
    }
    //sort(A.begin(),A.end());
    //for (int i = 0; i < N; i++) { maximum = max(maximum , A[i]);}
    //for (int i = 0; i < N; i++) { minimum = min(minimum , A[i]);}
    cout << ans << endl;
}