#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int i=a,inc=(b-a)/abs(b-a); i!=b ; i+=inc)
#define deb(x) cout<<#x<<"->"<<x<<endl;
#define print(arr,a,b) for(int i=a;i!=b;i++){cout<<arr[i]<<" ";}cout<<endl;
using ll=long long int;
int arr_min(int arr[],int a,int b){ int min=arr[0]; for(int i=a;i!=b;i++){if(min>arr[i]) min=arr[i];}return min;}
int arr_max(int arr[],int a,int b){ int max=arr[0]; for(int i=a;i!=b;i++){if(max<arr[i]) max=arr[i];}return max;}

signed main()
{
	ios_base::sync_with_stdio(false);   
    cin.tie(NULL);

	#ifndef ONLINE_JUDGE
      	freopen("input.txt", "r", stdin);
      	freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    // cin>>t;
    while(t-->0){
    	int k;
    	cin>>k;
    	ll sum=0;
    	for(int a=1;a<=k;a++)
    	{
    		for(int b=1;b<=k;b++)
    		{
    			for(int c=1;c<=k;c++)
    			{
                      int x=__gcd(b,c);
                      sum+=__gcd(x,a);
    			}
    		}
    	}
    	cout<<sum<<endl;
    	
    	
    }
    return 0;
}