#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;

int gcd(int a, int b) {
  while(a%b != 0) {
    int t = a % b;
    a = b;
    b = t;
  }
  return b;
}

int main() {
  int K;
  cin >> K;
  LL sum = 0;
  REP(a, K) {
    REP(b, K) {
      int g = gcd(a+1, b+1);
      REP(c, K) {
        sum += gcd(g, c+1);
      }
    }
  }
  cout << sum << endl;
} 