#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> P;

void printVec(std::vector<int> &vec) {
  std::cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;
}

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

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

  ll ans = 0;
  vector <int> x(3);
  int x1, x2, x3;
   for (x1 = 1; x1 <= k; x1++) {
     for (x2 = 1; x2 <= k; x2++) {
       for (x3 = 1; x3 <= k; x3++) {
         // ans = ans + gcd(gcd(x1, x2), x3);
         ans = ans + gcd(x1, gcd(x2, x3));
       }
     }
   }
  cout << ans << endl;
	return 0;
}