#include <iostream>
using namespace std;

typedef long long ll;
int dp[201][201][201];

int gcd(int a,int b)
{
  if (a%b==0)
    return b;
  else
    return gcd(b,a%b);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int l;
  cin >> l;

  int tmp;
  ll ans = 0L;
  for(int i=1;i<=l;i++){
    for(int j=i;j<=l;j++){
      for(int k=j;k<=l;k++){
        tmp = gcd(i, gcd(j,k));
        dp[i][j][k] = tmp;
        dp[i][k][j] = tmp;
        dp[j][i][k] = tmp;
        dp[j][k][i] = tmp;
        dp[k][i][j] = tmp;
        dp[k][j][i] = tmp;
      }
    }
  }

  for(int i=1;i<=l;i++){
    for(int j=1;j<=l;j++){
      for(int k=1;k<=l;k++){
        ans += dp[i][j][k];
      }
    }
  }

  cout << ans << endl;
  return 0;
}