#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll gcd(ll a, ll b) 
{ 
    // Everything divides 0  
    if (a == 0) 
       return b; 
    if (b == 0) 
       return a; 
   
    // base case 
    if (a == b) 
        return a; 
   
    // a is greater 
    if (a > b) 
        return gcd(a-b, b); 
    return gcd(a, b-a); 
} 
int main () {
	ll k;cin>>k;
	ll dp[k+1][k+1];ll i,j,k1;
	for(i=1;i<=k;i++)
	{
		for(j=1;j<=k;j++)
		dp[i][j]=gcd(i,j);
	}
	ll s=0;
	for(i=1;i<=k;i++)
	{
		for(j=1;j<=k;j++)
		{
			for(k1=1;k1<=k;k1++)
			{
				s+=gcd(i,dp[j][k1]);
			}
		}
	}
	cout<<s<<endl;
	return 0;
}

