#include <bits/stdc++.h>
using namespace std;

int find_gcd(int a, int b, int c) {
  int gcd;
  for (int i = a; i > 0; i--) {
    if (a % i == 0 && b % i == 0 && c % i == 0) {
      gcd = i;
      break;
    }
  }
  return gcd;
}

int main() {
  int K; cin >> K;
  
  int ans = 0;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      for (int k = 0; k <= K; k++) {
        ans += find_gcd(i, j, k);
      }
    }
  }
  cout << ans << endl;  
}