#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <map>
 
#define ST_ARR_LEN(array) (sizeof(array)/sizeof(*array))
 
using namespace std;
 
using ll = long long;
 
typedef stack<int> IntStack;
typedef queue<int> IntQueue;
typedef vector<int> IntVector;
typedef list<int> IntList;
 
typedef struct S{
  int a;
  int b;
} Object;
 
int euclideanGcd(int a, int b){
  if(a < b) return euclideanGcd(b, a);
  int c = a%b;
  while(c > 0){
    a = b;
    b = c;
    c = a%b;
  }
  return b;
}
 
int main(){
  int K;
  cin >> K;
  
  long long count = 0;
  for(int i=1;i<=K;i++){
    for(int j=1;j<=K;j++){
      for(int k=1;k<=K;k++){
        count += euclideanGcd(euclideanGcd(i, j), k);
      }
    }
  }
  
  cout << count << endl;
}