#include <stdio.h>
#include <string.h>

int gcd[201][201][201];
int gcd_(int a,int b){
   int tmp,r;
	  /* ���R�� a > b ���m�F�E���� */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ���[�N���b�h�̌ݏ��@ */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
	
	
int main(){

	int   i,j,k,z;
	int  N;
	long sum1=0,sum2=0;
	scanf("%d",&N);
	int m,n,o;
	for(i=1;i<=N;i++){
		for(j=1;j<=N;j++){
			for(k=1;k<=N;k++){
				if(gcd[i][j][k]==0){
					z=gcd_(j,k);
					gcd[i][j][k]=gcd_(i,z);
					//printf("%d,%d,%d:%d// ",i,j,k,gcd[i][j][k]);
					if(i==j&&j==k)sum2+=gcd[i][j][k];
					else{
						sum1+=gcd[i][j][k];
						gcd[i][k][j]=gcd[i][j][k];
						gcd[j][i][k]=gcd[i][j][k];
						gcd[j][k][i]=gcd[i][j][k];
						gcd[k][i][j]=gcd[i][j][k];
						gcd[k][j][i]=gcd[i][j][k];
					}
				}
				else {
					sum1+=gcd[i][j][k];
					//printf("%d,%d,%d:%d// ",i,j,k,gcd[i][j][k]);
				}
			}
		}
	}
	
	printf("%ld\n",sum1+sum2);
}