#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = long long unsigned;
using P = pair<int,int>;
const int INF=1001001001;
const int NMAX=8;
const int MOD=1000000007;
const int dbase=80*160;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}

int main(){
int k;
cin>>k;
int ans=0;
rep(i,k+1)rep(j,k+1)rep(l,k+1){
	ll gcdnow=gcd(i,j);
	gcdnow=gcd(gcdnow,l);
//	cout<<gcdnow<<endl;
	ans+=gcdnow;
}

cout<<ans;
}
