#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#include <bits/stdc++.h>
 
using namespace std;

ll gcd2(ll x, ll y, ll z){
    return gcd(gcd(x, y), z);
}
int main(void) {
    ll t, ans = 0;
    cin >> t;
    rep2(i, 1, t){
        rep2(j, 1, t){
            rep2(k, 1, t){
                ans += gcd2(i, j, k);
            }
        }
    }
    cout << ans << endl;
    return 0;
}