/*****************************************************
Name      :- Prashant                                                                   
Institute :- Birla Institute Of Technology , Mesra 
****************************************************/


//#define ENABLE_BOOST


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

#ifdef ENABLE_BOOST
#include <boost/multiprecision/cpp_int.hpp>
using cpp_int = boost::multiprecision::cpp_int;
#endif
#define ll long long int
#define ld long double
/* Constants */
constexpr ll MODVAL = 1e9 + 7;

template <typename T>
using vc = vector<T>;

template <typename T>
using vvc = vector<vector<T>>;

using vcl = vector<ll>;
using vcpl = vector<pair<ll, ll>>;
using vvcl = vector<vector<ll>>;
using vvcpl = vector<vector<pair<ll, ll>>>;
using vcd = vector<ld>;

using pl = pair<ll, ll>;

template <typename T>
using min_priority_queue = priority_queue<T, vc<T>, greater<T>>;

template <typename T>
using max_priority_queue = priority_queue<T, vc<T>, less<T>>;


/* Math Functions */

/**    1. Modular Multiplication      **/

ll modmult(ll a, ll b, ll mod = MODVAL) {
    ll res = 0; // Initialize result 
    a = a % mod; 
    while (b > 0) 
    { 
        // If b is odd, add 'a' to result 
        if (b % 2 == 1) 
            res = (res + a) % mod; 
  
        // Multiply 'a' with 2 
        a = (a * 2) % mod; 
  
        // Divide b by 2 
        b /= 2; 
    } 
  
    // Return result 
    return res % mod; 
}

/**       2. Modular Exponentiation     **/

ll powermod(ll x, ll n, ll mod = MODVAL){
    if(n == 0){
        return 1;
    }
    else if(n % 2){
        return (x * powermod(x, n - 1, mod)) % mod; 
    }
    ll temp = powermod(x, n / 2, mod);
    return (temp * temp) % mod;
}

/**       3. Exponentiation     **/

ll power(ll x, ll n){
    if(n == 0){
        return 1;
    }
    else if(n % 2){
        return (x * power(x, n - 1)); 
    }
    ll temp = power(x, n / 2);
    return (temp * temp);
}


/**       4. factorial     **/
vcl fac ;
ll inv(ll n, ll mod = MODVAL) {
    return powermod(n, mod - 2, mod);
}

ll fact(ll n, ll mod = MODVAL) {
    if(fac.size() == 0) {
        fac = vcl(1e6 + 1, 1);
        for(ll i = 1; i < fac.size(); ++i) {
            fac[i] = (i * fac[i - 1]) % mod;
        }
    }
    return fac[n];
}

/**       5.  combination     **/
ll ncr(ll n, ll r, ll mod = MODVAL) {
    if (n < r) {
        return 0;
    }
    ll ans = fact(n, mod);
    ans *= inv(fact(n - r, mod), mod);
    ans %= mod;
    ans *= inv(fact(r, mod), mod);
    ans %= mod;
    return ans;
}

/**          6. GCD           **/
ll gcd(ll a , ll b){
    if(b == 0)
        return a ;
    return gcd(b , a % b) ;
}

/**         7. SEIVE      **/

void seive(ll n , vc<bool> &prime){
    for(int i = 2 ; i * i <= n ; i++){
        for(int j = i * i ; j <= n ; j += i){
            if(prime[i])
                prime[j] = 0 ;
        }
    }
}

bool checkprime(ll p ,  vc<bool> &prime){
    return prime[p] ;
}


#define w(t)              long long t;cin>>t;while(t--)
#define foi(a , n)     for(long long i = a ; i<n ; i++)
#define foj(a , n)     for(long long j = a ; j<n ; j++)
#define fok(a , n)     for(long long k = a ; k<n ; k++)
#define fr(i , a , b)  for(long long i = b ; i>=a ; i-- )
#define all(v)          (v).begin() , (v).end()


int main(){
#ifndef ONLINE_JUDGE
    freopen("in.txt" ,  "r" ,  stdin) ;
#endif

    /***********CODE_HERE***********/
    ll x;
    cin >> x;
    ll sum = 0;
    foi(1,x+1){
    	foj(1,x+1){
    		fok(1,x+1){
    			sum=sum+gcd(gcd(i,j),k);
    		}
    	}
    }
    cout << sum;
    /**********END_OF_CODE**********/

    return 0 ;
}

Measured memory_bytes: 3640