#include <cmath>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <iostream>
#include <algorithm>
#include <numeric>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

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

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  unsigned k;
  cin >> k;

  ll sum = 0;
  rep(a, k) rep(b, k) rep(c, k) {
    sum += gcd(a + 1, gcd(b + 1, c + 1)); 
  }
  cout << sum << endl;
}