#include <bits/stdc++.h>
#define rep(i,n) for (int i = 1; i <= (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);

int k;
cin>>k;

ll ans=0;
rep(i,k)rep(j,k)rep(s,k){
  ans+=gcd(gcd(i,j),s);
}
cout<<ans<<endl;
return 0;
}