#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <utility>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

ll gcd(ll x, ll y)
{
   while(x!=y)
   {
       if(x>y) x=x-y;
       else
       	y=y-x;
   }
   return x;
   //辗转相除法
}

int main() {
	int n; cin >> n;
	long long sum = 0;
	for(int i = 1; i <= n; ++i){
		for(int j = 1; j <= n; ++j){
			for(int k = 1; k <= n; ++k){
				int x = gcd(j, k);
				int y = gcd(x, i);
				sum += y;
			}
		}
	}
	cout << sum << endl;
	return 0;
} 