#include <stdio.h>
#define swap(type, a, b) do{ type t = a; a = b; b = t; }while(0)

int gojo(int a, int b){
  if(!(a % b))
    return b;
  else
    gojo(b, a%b);
}

int main(){
  int k;  scanf("%d", &k);

  long long int sum = 0;
  for(int a=1; a<=k; a++)
    for(int b=1; b<=k; b++)
      for(int c=1; c<=k; c++)
	sum += gojo(a, gojo(b, c));

  printf("%lld\n", sum);

  return 0;
}

	 
