#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#define f first
#define s second
#define pb push_back
using namespace std;
long long const inf=1e18+5;
int const maxn=1005;
typedef long long ll;
typedef pair<int,int>P;
vector<P>p;
char s[maxn];
int num[30];
ll solve(ll n,ll x){
	ll num = n/x;
	return (x+num*x)*num>>1;
}
int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
int main(){
	int n,res=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			for(int k=1;k<=n;k++)
				res+=gcd((gcd(i,j)),k);
	printf("%d\n",res);
}
