#define pb push_back
#define ff first
#define ss second
#define ll long long
#define maxn 100005
#define mod 1000000007
#include <bits/stdc++.h>
using namespace std;



int main() {
    ll n, sum = 0;
    cin >> n;
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=n;j++){
            for(ll k=1;k<=n;k++){
                //cout << i <<  " "<< j << " "<< k << endl;
                ll x = __gcd(i, j);
                sum += __gcd(k, x);
            }
        }
    }
    cout << sum << '\n';
    return 0;
}
