#include<iostream>
using namespace std;

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

  return gcd(b, a % b);
}

int main(){
  int K;
  int a, c;
  int sum = 0;

  cin >> K;

  for (int i = 1; i < K + 1; i++){
    for (int j = 1; j < K + 1; j++){
      for (int k = 1; k < K + 1; k++){
        a = gcd(i,j);
        c = gcd(k,a);
        sum += c;
      }
    }
  }

  cout << sum << endl;

  return 0;


}
