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