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

int gcd_th(int a, int b, int c){
  return gcd(a, gcd(b, c));
}


int main(void){
  int K;
  cin >> K;
  long long sum = 0;
  for(int a = 1; a <= K; a++){
    for(int b = 1; b <= K; b++){
      for(int c = 1; c <= K; c++){
        sum += gcd_th(a, b, c);
      }
    }
  }
  cout << sum;
  
  return 0;
}