#include <stdio.h>

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

  for(int a=1;a<k+1;a++){
    for(int b=1;b<k+1;b++){
      while(b<1){
        int t = a % b;
        a = b;
        b = t;
      }
      for(int c=1;c<k+1;c++){
        while(c<0){
          int u = a % c;
          a = c;
          c = u;
        }
        sum += a;
      }
    }
  }
  printf("%ld",sum);
  return 0;
}