# include<iostream>
# include<cmath>
# include<algorithm>
using namespace std;

int main ()
{
	 int k;
	 cin>>k;
	 int sum =0;
	 for(int i=1;i<=k;i++)
	 {
	 	 for(int j=1;j<=k;j++)
	 	 {
	 	 	int g = __gcd(i,j);
	 	 	
	 	 	 for(int l=1;l<=k;l++)
	 	 	 {
	 	 	 	    sum += __gcd(g,l);
			   }
		  }
	 }
	 cout<<sum<<endl;
	
	
	
}