#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int gcd(int m, int n) {
  if(m < n) swap(m, n);
  if(n == 0) return abs(m);
  else return gcd(n, m % n);
}

int main() {
  int K; cin >> K;
  long long ans = 0;
  for(int a = 1; a <= K; a++) {
    for(int b = 1; b <= K; b++) {
      int ab = gcd(a, b);
      for(int c = 1; c <= K; c++) {
        int abc = gcd(ab, c);
        ans += abc;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
