#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < ( n ); ++i )
using namespace std;
using ll = long long;
using ull = unsigned long long;
using p  = pair<int, int>;
using vec_int = vector<int>;
using vec_str = vector<string>;
#define INF (1<<29)

void debug_input(vec_str& argv)
{
    // デバッグ用引数読み込み
    ifstream file("./input.txt");
    string str;
    while( getline(file, str) ) {
        argv.push_back(str);
    }
}

void debug_split_string(const string& str, vec_str& v)
{
    stringstream ss{str};
    string buf;
    while (getline(ss, buf, ' ')) {
        v.push_back(buf);
    }
}

void debug_split_int(const string& str, vec_int& v)
{
    stringstream ss{str};
    string buf;
    while (getline(ss, buf, ' ')) {
        istringstream ss(buf);
        int temp;
        ss >> temp;
        v.push_back(temp);
    }
}

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

int main()
{
    int N = 0;
	cin >> N;

  	ll ans = 0;
    
    int temp = 0;
    for(int i = 1; i <= N; ++i ) {
        
        for( int j = 1; j <= N; ++j ) {
            
            temp = gcd(i, j);
            
            for( int k = 1; k <= N; ++k ) {
                    int temp2 = gcd(k, temp);
                  	ans += temp2;
            }
        }
    }
        

    cout << ans << endl;
    
    return 0;
}