#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll n;
	cin>>n;
	ll total=0;
	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=n;j++){
			ll g=__gcd(i,j);
			for(ll k=1;k<=n;k++){
				ll temp=g;
				temp=g(k,temp);
				total+=temp;
			}
		}
	}
	cout<<total<<endl;
}