#include <bits/stdc++.h>

using namespace std;

const int M = 1e9 + 7;

int gcd(int a, int b , int c){
  return __gcd(a , __gcd(b , c));
}

int main() {
  int n ; cin>>n;
  int ans = 0;
  for(int i = 1 ; i <= n; ++i){
    for(int j = 1 ; j <= n; ++j){
      for(int k = 1 ; k <= n; ++k){
        ans += gcd(i , j , k);
      }
    }
  }
  cout<<ans<<"\n";
}