#include<iostream>
#include<string>

using namespace std;

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

int gcd(int a, int b, int c) {
    return gcd(gcd(a, b), c);
}

int main() {
  int n;
  cin >> n;
  int sum = 0;
  for (int i=0; i<n; ++i) {
      for(int j=0; j<n; ++j) {
          for(int k=0; k<n; ++k) {
              sum += gcd(i+1, j+1, k+1);
          }
      }
  }
  cout << sum << endl;
}
