#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

ll gcd(ll a, ll b){
  if (a < b)
    return gcd(b, a);
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

ll gcd(ll a, ll b, ll c){
  return gcd(a, gcd(b, c));
}


int main(void){
  ll k;
  cin >> k;
  

  ll res = 0;
  for (int i = 0; i < k; i++){
    for (int j = 0; j < k; j++){
      for (int l = 0; l < k; l++){
        res += gcd(i + 1, j + 1, l + 1);
      }
    }
  }

  cout << res << endl;
  
  

  return 0;
}
