#include <bits/stdc++.h>
using namespace std;

int max_my(int x,int y,int z){
  int answer = x;
  if (x < y){
    answer = y;
    if (y < z){
      answer = z;
    }
  }
  else if (x < z){
    answer = z;
  }
  return answer;
}

int gcd(int a,int b,int c){
  int G = 1;
  for (int i = 1; i < max_my(a, b, c) + 1; i++){
    if (a % i == 0 && b % i == 0 && c % i == 0){
      G = i;
    }
  }
  return G;
}
    
int main(){
  int K;
  cin >> K;
  int sum = 0;
  for (int i = 1; i < K + 1; i++){
    for (int j = 1; j < K + 1; j++){
      for (int k = 1; k < K + 1; k++){
        sum += gcd(i, j, k);
      }
    }
  }
  cout << sum << endl;
  return 0;
}
  