#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define vi vector<int>
#define vii vector<int, int>
#define po pop_back
#define hell 1000000007
using namespace std;

int a[201][201];

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

void filla(){
	for(int i=1;i<201;i++){
		for(int j=1;j<201;j++){
			if(a[i][j]!=0) continue;
			else{
				a[i][j] = gcd(i,j);
				a[j][i] = a[i][j];
			}
		}
	}
}

void solve(){
	memset(a,0,sizeof(a));
	filla();
	int k;
	cin>>k;
	ll ans = 0;
	for(int i=1;i<k+1;i++){
		for(int j=1;j<k+1;j++){
			for(int l=1;l<k+1;l++){
				ans+=a[i][a[j][l]];
			}
		}
	}
	cout<<ans;
}

int main(){
	int t = 1;
	//cin>>t;
	while(t--){
		solve();
	}
}