#include <iostream>
#include <algorithm>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
typedef long double ld;
using ll=long long;
using namespace std;
const auto mod=1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  int k; cin >> k;
  int sum=0;
  rep(i,1,k+1){
  	rep(j,1,k+1){
  		rep(l,1,k+1){
  			int res = __gcd(i,j);
  			sum+=__gcd(res,l);
  		}
  	}
  }
  cout << sum << endl;
 }