#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>
using namespace std;

// ABC 162 c

long long GCD(long long x, long long y){
  if (y == 0) return x;
  else return GCD(y, x % y);
}

int main() {
  int k;
  cin >> k;
  int res = 0;
  for (int a = 1; a <= k; a++) {
    for (int b = 1; b <= k; b++) {
      for (int c = 1; c <= k; c++) {
        res += GCD(GCD(a, b), c);
      }
    }
  }
  cout << res << "\n";
}
