#include <bits/stdc++.h>
using namespace std;

int gcd(int x,int y,int z){
   	int r;
   	r=x%y;
   	if(r==0)
   	   r=n;
   	   r=n%z;
   	   if(r==0) return z;
   	   else return gcd(z,r);
   	else
   	   return gcd(y,r);
   }
int main(){
	int a,b,c;
	int k,sum=0;
	cin>>k;
	
	for (a=1; a<=k; a++){
   		for (b=1; b<=k; b++){
      		for (c=1; c<=k; c++){
          		sum += gcd(a, b, c)；
      		}
   		}
	}
	cout<<sum;
	return 0;
}