#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll ans,n;
int main(){
	cin>>n;
	for(int a=1;a<=n;a++)
		for(int b=1;b<=n;b++)
			for(int c=1;c<=n;c++){
				ans+=__gcd(__gcd(a,b),c);
			}
	cout<<ans;
	return 0;
}