#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

ll GCD(ll a, ll b){
    if(a < b) return GCD(b,a);
    if(b == 0) return a;
    else return GCD(b,a%b);
}

int main(){
  ll K;
  cin >> K;
  ll ans = 0;
  for(int i = 1;i <= K;i++){
    for(int j = 1;j <= K;j++){
      for(int k = 1;k <= K;k++){
        ans += GCD(GCD(i,j),k);
      }
    }
  }
  cout << ans << endl;
}
