#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int mod=1000000007;
int main(){
	ios;
	int n,i,j,k,s=0,x;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			x=__gcd(i,j);
			for(k=1;k<=n;k++)
			s+=__gcd(x,k);
		}
	}
	cout<<s;
	return 0;
}