#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
#define all(c) (c).begin(), (c).end()
#define rep( i, a, n ) for( int i=a; i<n; i++ )
#define repp( i, a, n, p ) for( int i=a; i<n; i+=p )
#define per( i, a, n ) for( int i=n-1; i>=a; i--)

int main () {
    int n;
    cin >> n;
    ll sum =0;

    rep ( i, 1, n+1 ) {
        rep ( j, 1, n+1 ) {
            rep ( k, 1, n+1 ) {
                sum += gcd ( i, gcd ( k, j ) );
            }
        }
    }
    cout << sum << endl;
}
