#include <bits/stdc++.h>
 
using namespace std;
 
#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define TRAV(a, x) for(const auto& a : x)
#define ALL(x) x.begin(), x.end()
#define NEXT_PERM(x) while(next_permutation(ALL(x))) // 순열 알고리즘(오름)
#define PREV_PERM(x) while(prev_permutation(ALL(x))) // 순열 알고리즘(내림)
#define PRINT(x) cout << x
#define PRINT_LN(x) cout << x << endl;
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")
 
typedef long long int ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
 
void solve() {
  int n;
  cin >> n;
  int result = 0;
  REP(i,n){
    REP(j,n){
      REP(k,n){
        result += gcd(i+1, gcd(j+1, k+1));
      }
    }
  }
  cout << result;
}
 
int main() {
  solve();
  return 0;
}
 