#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
//int A[4005]={0};
int gcd(int x,int y,int z){
  int m=min(x,min(y,z));
  while(!(x%m==0&&y%m==0&&z%m==0))m--;
  return m;
}


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