#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
// #ifndef ONLINE_JUDGE
// #include "debug.cpp"
// #endif
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }


int32_t main(){
    
  fast;
  int k; cin >> k;

  int sum = 0;

  for(int i=1;i<=k;i++){
    for(int j=1;j<=k;j++){
      for(int m=1;m<=k;m++){
        int g = __gcd(i,j);
        g = __gcd(g,m);
        sum+=g;
      }
    }
  }

  cout << sum << '\n';

  

  return 0;
}