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

int main() {
  
  int K;
  cin >> K;
  int sum = 0;
  
  for (int a = 1; a < K + 1; a++) {
    for (int b = 1; b < K + 1; b++) {
      for (int c = 1; c < K + 1; c++) {
        sum += __gcd(a, __gcd(b, c));
      }
    }
  }
  
  cout << sum << endl;
  

}
