#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
#include <random>
#include <bitset>
#include <chrono>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#ifndef ONLINE_JUDGE
// #include "debug.h"
#else
// #define debug(...) 42
#endif

const int M = 1e5+5;
const int MD= 1e9+7;


int main() {
	fast_cin();
	int t=1;
	// cin>>t;
	while(t--)
	{
		int k,su=0;
		cin>>k;
		for(int i=1;i<=k;i++){
			for(int j=1;j<=k;j++){
				for(int l=1;l<=k;l++){
					su+=__gcd(i,__gcd(j,l));
				}
			}
		}
		cout<<su<<endl;
	}	
	return 0;
}