    #include <stdio.h>
    #include <math.h>
    void main()
    {
      int N,t,i,k,m,ans,r;
      scanf("%d", &N);
      for(i=0;i<N;i++){
        for(j=0;j<N;j++){
          for(k=0;k<N;k++){
            n=i;m=j;
            if (n > m) {
              t = m;
              m = n;
              n = t;
            }
            while ((r = m % n) != 0) {
              m = n;
              n = r;
            }
            if(n > j) {
              t = j;
              j = n;
              n = t;
            }
            while((r = j % n) != 0) {
              j = n;
              n = r;
            }
            sum+=n;
          }
        }
      }
      printf("%d", sum);
    }