#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
using ll = long long;

int gcd(int p, int q){
	while(q != 0){
    	int r = p % q;
      	p = q;
      	q = r;
    }
  	return p;
}

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

	cout << ans << endl;  
}