#include <bits/stdc++.h>

using namespace std;

int dgcd(int a,int b){
	int tmp;
	if(a < b){
		tmp = a;
		a = b;
		b = tmp;
	}
	while(a%b != 0){
		tmp = a % b;
		a = b;
		b = tmp;
	}
	return b;
}
int gcd(int a,int b,int c){
	int ab = dgcd(a,b);
	int re = dgcd(ab,c);
	return re;
}
int main(void)
{
	int k;
	cin>>k;
	long long ans = 0;
	for(int a = 1; a <= k; a++){
		for(int b = 1; b <= k; b++){
			for(int c = 1; c <= k; c++){
				ans+=gcd(a,b,c);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

