#include<bits/stdc++.h>
#define io ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long int ll;
using namespace std;
int gcd(int a,int b){
	if(b == 0)
		return a;
	else
		return gcd(b,a%b);
}
int g(int a,int b,int c){
	int d = gcd(a,b);
	return gcd(d,c);
}
int main(){
	io;
	int k;
	cin >> k;
	ll ans = 0;
	for(int i = 1;i <= k;++i){
		for(int j = 1;j <= k;++j){
			for(int t = 1;t <= k;++t){
				ans += g(i,j,t);
			}
		}
	}
	cout << ans;
	return 0;
}