#include <stdio.h>

int main(void)
{
  int k, sum, p, q, aa, bb, cc;
  
  scanf("%d", &k);
  
  for(int a = 1; a <= k; a++) {
    aa = a;
    for(int b = 1; b <= k; b++) {
      bb = b;
      // a, bのGCD
      if(aa < bb) {
        q = aa;
        aa = bb;
        bb = q;
      }
      while(aa % bb != 0) {
       p = aa % bb;
       aa = bb;
       bb = p;
      }
      for(int c = 1; c <= k; c++) {
       cc = c;
        if(bb < cc) {
        q = bb;
        bb = cc;
        cc = q;
      }
       while(b % c != 0) {
       p = bb % cc;
       bb = cc;
       cc = p;
      }
        sum += cc;
      }
    }
  }
  
  printf("%d", sum);
  
  return 0;
}