#include <bits/stdc++.h>

#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define pii pair<int,int>
#define vi vector<int>
#define vit vector<int>::iterator it
#define mii map<int,int>
#define mis map<int,string>
#define msi map<string,int>
#define X first
#define Y second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
#define sz(v) (int)(v.size())
#define si set<int>
#define ms(a,f) memset((a),(f),sizeof (a))

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int inf=0x7f7f7f7f;
const int N=1e5+10;
int n;
int main() {
	ll ans=0;
	cin>>n;
	rep(i,1,n) rep(j,1,n) rep(k,1,n) ans+=__gcd(i,__gcd(j,k)); 
	cout<<ans<<endl;
	return 0;
}