#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>
#define loop(i, l, r) for(i=l; i<r; i++)/*Instead of function, (for).*/
#define rep(i,r) for(i=0; i<r; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long int lli;
/*Return Combination ,(nCr)*/
int combi(int n, int r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
/*Return gcd(a, b)*/
lli gcd(lli a, lli b){
	if(b == 0) return a;
	else return gcd(b, a % b);
}
//qsort�֐��Ɏg��compare�֐�,(long long int, int, double�^)
int compare_lli(const void *a, const void *b)
{
    return *(lli*)a - *(lli*)b;
}
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
int compare_double(const void *a, const void *b)
{
    return *(double*)a - *(double*)b;
}/****************<Data�\���̂̐錾>*********************/
typedef struct data{
	int x;
	char c[2];
}Data;
/*******************************************************/
int compare_struct(const void *a, const void *b){
  Data *A = (Data *)a;
  Data *B = (Data *)b;
  return ((A->x) - (B->x));
}
/*qsort(array, 10, sizeof(int/lli/double/struct data), compare_int/double/lli/struct);*/
/*qsort(�z��/�\���̔z��), �v�f��, sizeof(�z��̌^), compare_�֐��̖��O);*/


//2�̔z�񂪈�v���邩�̔���_(return��v��0,�s��v���P)
int chek(int *tmp1, int *tmp2, int n){
	int i;
	for(i=0; i<n; i++){
		if(tmp1[i] != tmp2[i]){
			return 1;
		}
	}
	return 0;
}
/*��Βl��Ԃ�(Abs)�֐�*/
int Abs(int a){
	if(a>=0) return a;
	else return -1*a;
}
/**********************************************************************/

lli n;
lli ans(lli x, lli *a, lli i){
	x = gcd(x, a[i]);
	if(x == 1) return (i+1);
	i++;
	if(i >= n) return x;
	return ans(x, a, i);
}
int main(void)
{
	long long int k, i, j, m, sum=0, ans;
	scanf("%lld", &k);
	loop(i, 1, k+1){
		loop(j, 1, k+1){
			loop(m, 1, k+1){
				ans = gcd(gcd(i,j), m);
				sum += ans;
			}
		}
	}
	printf("%lld", sum);
	return 0;
}