
	#include <bits/stdc++.h>
using namespace std;
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	#define int long long 
	//using namespace std;
template<typename T> T gcd(T a, T b){ if(b == 0) return a; return gcd(b, a % b); }
	
	
	int gcd3(int a,int b,int c)
	{
		return gcd(gcd(a,b),c);
	}
	signed main()
	{
		std::ios::sync_with_stdio(false);
		int n;
		cin>>n;
		int sum = 0 ; 
		for(int i=1;i<=n;++i)
		{
			for(int j=1;j<=n;++j)
		{
			for(int k=1;k<=n;++k)
		{
			sum += gcd3(i,j,k) ;
		}
		}
		}
		cout<<sum ; 
		return 0;
	}
