/* author   : mpily :-()
title : Competing.cpp
time :Fri Apr 10 17:19:34 2020

*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
int dp[201][201];//dp[i][0] = number of R.. [i][1] number of B...[i][2] number of G
int getgcd(int a, int b){
	if(dp[a][b]){
		return dp[a][b];
	}
	else{
		int g = __gcd(a,b);
		dp[a][b] = g;
		dp[b][a] = g;
	}
	return dp[a][b];
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int k;
	cin>>k;
	for(int i = 0; i <= k;++i)for(int j = 0; j <= k; ++j)dp[i][j] = 0;
	long long ans = 0;
	for(int i = 1; i <= k; ++i){
		for(int j = 1; j <= k; ++j){
			for(int l = 1; l <= k; ++l){
				int p1 = getgcd(i,j);
				int t = getgcd(p1,l);
				ans+=t;	
			}
		}
	}
	cout<<ans<<"\n";
	return 0;
}
