#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <math.h>
#include <queue>
using namespace std;
typedef long long ll;

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

  return gcd(b, a % b);
}

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

  ll sum = 0;
  for (int a = 1; a <= N; a ++) {
    for (int b = 1; b <= N; b ++) {
      for (int c = 1; c <= N; c ++) {
        sum += gcd(gcd(a, b), c);
      }
    }
  }
  cout << sum << endl;
  return 0;
}