
// Problem : C - Sum of gcd of Tuples (Easy)
// Contest : AtCoder Beginner Contest 162
// URL : https://atcoder.jp/contests/abc162/tasks/abc162_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;

signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
    	int k;
    	cin>>k;
    	int gcd;
    	int result;
    	int ct = 0;
    	
    	for(int i=1;i<=k;++i)
    	{
    		for(int j=1;j<=k;++j)
    		{
    			for(int l=1;l<=k;++l)
    			{
    				result = __gcd(i,__gcd(j,l));
    				
    				ct+=result;
    			}
    		}
    	}
    	cout<<ct;
    }
    return 0;
}

