#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

ll gcd(ll x,ll y) { return y ? gcd(y,x%y) : x; }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  ll k;cin>>k;
  ll s=0;
  repeat(a,1,k+1) {
    repeat(b,1,k+1) {
      repeat(c,1,k+1) {
	s+=gcd(a,gcd(b,c));
      }
    }
  }
  cout << s <<endl;
  return 0;
}
