#include<stdio.h>

int main(void){
  int K; scanf("%d",&K);
  long int ans = 0;

  for(int a = 1;a <= K;a++){
    for(int b = 1;b <= K;b++){
      for(int c = 1;c <= K;c++){
        int a_copy = a,b_copy = b;

        //a,b
        int g_ab,r,tmp;
        if(a_copy < b_copy){
          tmp = a_copy;
          a_copy = b_copy;
          b_copy = tmp;
        }
        r = a_copy % b_copy;
        while(r > 0){
          a_copy = b_copy;
          b_copy = r;
          r = a_copy % b_copy;
        }
        g_ab = b_copy;

        //b,c
        int b_copy = b,c_copy = c;
        if(b_copy < c_copy){
          tmp = b_copy;
          b_copy = c_copy;
          c_copy = tmp;
        }
        r = b_copy % c_copy;
        while(r > 0){
          b_copy = c_copy;
          c_copy = r;
          r = b_copy % c_copy;
        }
        g_bc = c_copy;

        //g_ab,g_bc
        if(g_ab < g_bc){
          tmp = g_ab;
          g_ab = g_bc;
          g_bc = tmp;
        }
        r = g_ab % g_bc;
        while(r > 0){
          g_ab = g_bc;
          g_bc = r;
          r = g_ab % g_bc;
        }
        g_abc = g_bc;
        ans += g_abc;
      }
    }
  }
  printf("%d",ans);
  return 0;
}