#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }

ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x; }

int main(){
    int k; cin >> k;
    ll ans = 0;
    for(int i = 1; i<= k; i++) for(int j = 1; j<= k; j++) for(int l = 1; l<= k; l++){
        ans += gcd(i,gcd(j,l));
    }
    cout << ans << endl;
    return 0;
}
