#include <bits/stdc++.h>
#include <iomanip>
#include<algorithm>
#define ll long long
using namespace std;

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