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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

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

    lint ans = 0;
    for_(a,1,K+1) for_(b,1,K+1) for_(c,1,K+1) {
        int x = __gcd(a, b);
        x = __gcd(x, c);
        ans += x;
    }
    cout << ans << endl;
}