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

int gcd(int a, int b) { return b?gcd(b,a%b):a;}

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